package cn.stylefeng.team.form.modular.component.controller;

import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
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.form.modular.component.entity.FormComponentCategory;
import cn.stylefeng.team.form.modular.component.pojo.request.FormComponentCategoryRequest;
import cn.stylefeng.team.form.modular.component.service.FormComponentCategoryService;
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 FormComponentCategoryController {

    @Resource
    private FormComponentCategoryService formComponentCategoryService;

    @PostResource(name = "添加表单组件分类", path = "/formComponentCategory/add")
    public ResponseData<FormComponentCategory> add(@RequestBody @Validated(FormComponentCategoryRequest.add.class) FormComponentCategoryRequest formComponentCategoryRequest) {
        formComponentCategoryService.add(formComponentCategoryRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除表单组件分类", path = "/formComponentCategory/delete")
    public ResponseData<?> delete(@RequestBody @Validated(FormComponentCategoryRequest.delete.class) FormComponentCategoryRequest formComponentCategoryRequest) {
        formComponentCategoryService.del(formComponentCategoryRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除表单组件分类", path = "/formComponentCategory/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) FormComponentCategoryRequest formComponentCategoryRequest) {
        formComponentCategoryService.batchDelete(formComponentCategoryRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑表单组件分类", path = "/formComponentCategory/edit")
    public ResponseData<?> edit(@RequestBody @Validated(FormComponentCategoryRequest.edit.class) FormComponentCategoryRequest formComponentCategoryRequest) {
        formComponentCategoryService.edit(formComponentCategoryRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看表单组件分类详情", path = "/formComponentCategory/detail")
    public ResponseData<FormComponentCategory> detail(@Validated(FormComponentCategoryRequest.detail.class) FormComponentCategoryRequest formComponentCategoryRequest) {
        return new SuccessResponseData<>(formComponentCategoryService.detail(formComponentCategoryRequest));
    }

    @GetResource(name = "获取表单组件分类列表", path = "/formComponentCategory/list")
    public ResponseData<List<FormComponentCategory>> list(FormComponentCategoryRequest formComponentCategoryRequest) {
        return new SuccessResponseData<>(formComponentCategoryService.findList(formComponentCategoryRequest));
    }

    @GetResource(name = "获取表单组件分类列表（带分页）", path = "/formComponentCategory/page")
    public ResponseData<PageResult<FormComponentCategory>> page(FormComponentCategoryRequest formComponentCategoryRequest) {
        return new SuccessResponseData<>(formComponentCategoryService.findPage(formComponentCategoryRequest));
    }

}
