package cn.stylefeng.team.portal.modular.management.controller;

import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.team.portal.modular.management.entity.PortalNewsCategory;
import cn.stylefeng.team.portal.modular.management.pojo.request.PortalNewsCategoryRequest;
import cn.stylefeng.team.portal.modular.management.service.PortalNewsCategoryService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@ApiResource(name = "新闻的分类")
public class PortalNewsCategoryController {

    @Resource
    private PortalNewsCategoryService portalNewsCategoryService;

    @PostResource(name = "添加新闻的分类", path = "/portalNewsCategory/add")
    public ResponseData<PortalNewsCategory> add(@RequestBody @Validated(PortalNewsCategoryRequest.add.class) PortalNewsCategoryRequest portalNewsCategoryRequest) {
        portalNewsCategoryService.add(portalNewsCategoryRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除新闻的分类", path = "/portalNewsCategory/delete")
    public ResponseData<?> delete(@RequestBody @Validated(PortalNewsCategoryRequest.delete.class) PortalNewsCategoryRequest portalNewsCategoryRequest) {
        portalNewsCategoryService.del(portalNewsCategoryRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除新闻的分类", path = "/portalNewsCategory/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) PortalNewsCategoryRequest portalNewsCategoryRequest) {
        portalNewsCategoryService.batchDelete(portalNewsCategoryRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑新闻的分类", path = "/portalNewsCategory/edit")
    public ResponseData<?> edit(@RequestBody @Validated(PortalNewsCategoryRequest.edit.class) PortalNewsCategoryRequest portalNewsCategoryRequest) {
        portalNewsCategoryService.edit(portalNewsCategoryRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看新闻的分类详情", path = "/portalNewsCategory/detail")
    public ResponseData<PortalNewsCategory> detail(@Validated(PortalNewsCategoryRequest.detail.class) PortalNewsCategoryRequest portalNewsCategoryRequest) {
        return new SuccessResponseData<>(portalNewsCategoryService.detail(portalNewsCategoryRequest));
    }

    @GetResource(name = "新闻分类树列表", path = "/portalNewsCategory/treeList")
    public ResponseData<List<PortalNewsCategory>> treeList(PortalNewsCategoryRequest portalNewsCategoryRequest) {
        return new SuccessResponseData<>(portalNewsCategoryService.treeList(portalNewsCategoryRequest));
    }

}
