package com.zcxk.process.controller;


import com.zcxk.model.AjaxMessage;
import com.zcxk.model.ResultStatus;
import com.zcxk.process.dto.TaskUserDTO;
import com.zcxk.process.entity.UserForm;
import com.zcxk.process.service.UserFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/workflow/form/")
@Api(tags = "工作流表单管理")
public class UserFormController {

    @Autowired
    UserFormService userFormService;

    @GetMapping("/getTaskForm")
    @ApiOperation(value = "获取任务表单")
    public AjaxMessage<UserForm> getTaskForm(@ApiParam(value = "任务ID", required = true) @RequestParam(required = true) String taskId) {
        UserForm taskForm = userFormService.getTaskUserForm(taskId);
        return new AjaxMessage<>(ResultStatus.OK, taskForm);
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取表单列表")
    public AjaxMessage<List<UserForm>> getUserFormList() {
        List<UserForm> list = userFormService.getUserFormList();
        return new AjaxMessage<>(ResultStatus.OK, list);
    }
    @PostMapping("/getTaskUsers")
    @ApiOperation(value = "保存任务参与者")
    public AjaxMessage getTaskUsers(@RequestBody TaskUserDTO taskUserDTO) {

        return new AjaxMessage(ResultStatus.OK,userFormService.getTaskUsers(taskUserDTO));
    }

    @GetMapping("/{formKey}")
    @ApiOperation(value = "获取表单详情")
    public AjaxMessage<UserForm> getFormDetail(
            @ApiParam(value = "表单key", required = true) @PathVariable(required = true) String formKey,
            @ApiParam(value = "场景Id,调用时同工单对应场景", required = false) @RequestParam(required = false) Integer channelId
    ) {
        UserForm result = userFormService.getUserFormDetail(formKey, channelId);
        return new AjaxMessage<>(ResultStatus.OK, result);
    }

}
