package org.xyzh.news.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xyzh.api.news.category.ResourceCategoryService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.resource.TbResourceCategory;

/**
 * @description 资源分类控制器
 * @filename ResourceCategoryController.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-15
 */
@RestController
@RequestMapping("/news/categorys")
public class ResourceCategoryController {
    private static final Logger logger = LoggerFactory.getLogger(ResourceCategoryController.class);

    @Autowired
    private ResourceCategoryService resourceCategoryService;

    /**
     * 获取分类列表
     */
    @GetMapping("/list")
    public ResultDomain<TbResourceCategory> getCategoryList() {
        return resourceCategoryService.getAllCategories();
    }

    /**
     * 根据ID获取分类详情
     */
    @GetMapping("/category/{categoryID}")
    public ResultDomain<TbResourceCategory> getCategoryById(@PathVariable String categoryID) {
        return resourceCategoryService.getCategoryById(categoryID);
    }

    /**
     * 创建分类
     */
    @PostMapping("/category")
    public ResultDomain<TbResourceCategory> createCategory(@RequestBody TbResourceCategory category) {
        return resourceCategoryService.createCategory(category);
    }

    /**
     * 更新分类
     */
    @PutMapping("/category")
    public ResultDomain<TbResourceCategory> updateCategory(@RequestBody TbResourceCategory category) {
        return resourceCategoryService.updateCategory(category);
    }

    /**
     * 删除分类
     */
    @DeleteMapping("/category/{categoryID}")
    public ResultDomain<Boolean> deleteCategory(@PathVariable String categoryID) {
        return resourceCategoryService.deleteCategory(categoryID);
    }

    /**
     * 更新分类状态
     */
    @PutMapping("/category/{categoryID}/status")
    public ResultDomain<TbResourceCategory> updateCategoryStatus(@PathVariable String categoryID, @RequestParam Integer status) {
        return null;
        // return resourceCategoryService.updateCategoryStatus(categoryID, status);
    }

    /**
     * 获取分类树
     */
    @GetMapping("/tree")
    public ResultDomain<TbResourceCategory> getCategoryTree() {
        return resourceCategoryService.getCategoryTree();
    }

    /**
     * 获取子分类
     */
    @GetMapping("/category/{parentID}/children")
    public ResultDomain<TbResourceCategory> getChildCategories(@PathVariable String parentID) {
        return resourceCategoryService.getCategoriesByParent(parentID);
    }
}
