package cn.stylefeng.team.project.modular.business.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.project.api.entity.BusinessCategory;
import cn.stylefeng.team.project.modular.business.pojo.request.BusinessCategoryRequest;
import cn.stylefeng.team.project.modular.business.service.BusinessCategoryService;
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 BusinessCategoryController {

    @Resource
    private BusinessCategoryService businessCategoryService;

    @PostResource(name = "添加业务分类", path = "/businessCategory/add")
    public ResponseData<BusinessCategory> add(
            @RequestBody @Validated(BusinessCategoryRequest.add.class) BusinessCategoryRequest businessCategoryRequest) {
        businessCategoryService.add(businessCategoryRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除业务分类", path = "/businessCategory/delete")
    public ResponseData<?> delete(
            @RequestBody @Validated(BusinessCategoryRequest.delete.class) BusinessCategoryRequest businessCategoryRequest) {
        businessCategoryService.del(businessCategoryRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除业务分类", path = "/businessCategory/batchDelete")
    public ResponseData<?> batchDelete(
            @RequestBody @Validated(BaseRequest.batchDelete.class) BusinessCategoryRequest businessCategoryRequest) {
        businessCategoryService.batchDelete(businessCategoryRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑业务分类", path = "/businessCategory/edit")
    public ResponseData<?> edit(
            @RequestBody @Validated(BusinessCategoryRequest.edit.class) BusinessCategoryRequest businessCategoryRequest) {
        businessCategoryService.edit(businessCategoryRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看业务分类详情", path = "/businessCategory/detail")
    public ResponseData<BusinessCategory> detail(
            @Validated(BusinessCategoryRequest.detail.class) BusinessCategoryRequest businessCategoryRequest) {
        return new SuccessResponseData<>(businessCategoryService.detail(businessCategoryRequest));
    }

    @GetResource(name = "获取业务分类列表", path = "/businessCategory/list")
    public ResponseData<List<BusinessCategory>> list(BusinessCategoryRequest businessCategoryRequest) {
        return new SuccessResponseData<>(businessCategoryService.findList(businessCategoryRequest));
    }

    @GetResource(name = "获取业务树", path = "/businessCategory/getBusinessTree")
    public ResponseData<List<BusinessCategory>> getBusinessTree(BusinessCategoryRequest businessCategoryRequest) {
        return new SuccessResponseData<>(businessCategoryService.getBusinessTree(businessCategoryRequest));
    }

}
