package cn.stylefeng.team.form.modular.manage.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.manage.entity.FormTemplate;
import cn.stylefeng.team.form.modular.manage.pojo.request.FormTemplateRequest;
import cn.stylefeng.team.form.modular.manage.service.FormTemplateService;
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 FormTemplateController {

    @Resource
    private FormTemplateService formTemplateService;

    @PostResource(name = "添加表单模板", path = "/formTemplate/add", requiredPermission = true, requirePermissionCode = "FORM_ADD_TO_TEMPLATE")
    public ResponseData<FormTemplate> add(@RequestBody @Validated(FormTemplateRequest.add.class) FormTemplateRequest formTemplateRequest) {
        formTemplateService.add(formTemplateRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除表单模板", path = "/formTemplate/delete", requiredPermission = true, requirePermissionCode = "FORM_TEMPLATE_MANAGER")
    public ResponseData<?> delete(@RequestBody @Validated(FormTemplateRequest.delete.class) FormTemplateRequest formTemplateRequest) {
        formTemplateService.del(formTemplateRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除表单模板", path = "/formTemplate/batchDelete", requiredPermission = true, requirePermissionCode = "FORM_TEMPLATE_MANAGER")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) FormTemplateRequest formTemplateRequest) {
        formTemplateService.batchDelete(formTemplateRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑表单模板", path = "/formTemplate/edit", requiredPermission = true, requirePermissionCode = "FORM_TEMPLATE_MANAGER")
    public ResponseData<?> edit(@RequestBody @Validated(FormTemplateRequest.edit.class) FormTemplateRequest formTemplateRequest) {
        formTemplateService.edit(formTemplateRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看表单模板详情", path = "/formTemplate/detail", requiredPermission = true, requirePermissionCode = "FORM_TEMPLATE_MANAGER")
    public ResponseData<FormTemplate> detail(@Validated(FormTemplateRequest.detail.class) FormTemplateRequest formTemplateRequest) {
        return new SuccessResponseData<>(formTemplateService.detail(formTemplateRequest));
    }

    @GetResource(name = "获取表单模板列表", path = "/formTemplate/list")
    public ResponseData<List<FormTemplate>> list(FormTemplateRequest formTemplateRequest) {
        return new SuccessResponseData<>(formTemplateService.findList(formTemplateRequest));
    }

    @GetResource(name = "获取表单模板列表（带分页）", path = "/formTemplate/page")
    public ResponseData<PageResult<FormTemplate>> page(FormTemplateRequest formTemplateRequest) {
        return new SuccessResponseData<>(formTemplateService.findPage(formTemplateRequest));
    }

}
