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

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.api.entity.FormItem;
import cn.stylefeng.team.form.api.pojo.FormDesignVo;
import cn.stylefeng.team.form.modular.manage.request.FormConfigRequest;
import cn.stylefeng.team.form.modular.manage.service.FormItemService;
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 FormItemController {

    @Resource
    private FormItemService formItemService;

    @GetResource(name = "获取表单元素配置信息", path = "/formItem/getFormConfig")
    public ResponseData<FormDesignVo> getFormConfig(@Validated(FormConfigRequest.getItemList.class) FormConfigRequest formItemRequest) {
        return new SuccessResponseData<>(formItemService.getFormConfig(formItemRequest));
    }

    @PostResource(name = "更新表单元素列表", path = "/formItem/saveOrUpdateFormConfig")
    public ResponseData<FormItem> saveOrUpdateFormConfig(
            @RequestBody @Validated(FormConfigRequest.saveOrUpdateItems.class) FormConfigRequest formItemRequest) {
        formItemService.saveOrUpdateFormConfig(formItemRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "获取表单定义下的所有字段信息列表", path = "/formItem/getFormFieldList")
    public ResponseData<List<FormItem>> getFormFieldList(
            @Validated(FormConfigRequest.getItemList.class) FormConfigRequest formItemRequest) {
        return new SuccessResponseData<>(formItemService.getFormFieldList(formItemRequest));
    }

}
