package com.qmth.sop.server.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.bean.result.FlowFormWidgetResult;
import com.qmth.sop.business.bean.result.FormWidgetResult;
import com.qmth.sop.business.cache.CommonCacheService;
import com.qmth.sop.business.service.TDFormWidgetService;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.TFCustomTypeEnum;
import com.qmth.sop.common.util.Result;
import com.qmth.sop.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "系统控件Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_WIDGET)
public class TDFormWidgetController {

    @Resource
    CommonCacheService commonCacheService;

    @Resource
    TDFormWidgetService tdFormWidgetService;

    @ApiOperation(value = "控件查询列表")
    @ApiResponses({@ApiResponse(code = 200, message = "控件查询列表信息", response = FormWidgetResult.class)})
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result list() {
        return ResultUtil.ok(commonCacheService.formWidgetCache());
    }

    @ApiOperation(value = "流程控件查询")
    @ApiResponses({@ApiResponse(code = 200, message = "流程控件查询", response = FlowFormWidgetResult.class)})
    @RequestMapping(value = "/flow/select", method = RequestMethod.POST)
    public Result flowSelect(@ApiParam(value = "流程类型", required = true) @RequestParam TFCustomTypeEnum flowType,
                             @ApiParam(value = "表单步骤") @RequestParam(required = false) Integer formSetup) {
        return ResultUtil.ok(tdFormWidgetService.flowWidgetQuery(flowType, formSetup));
    }
}
