package com.zcloud.safetyDutyList.web.tasklist;

import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.safetyDutyList.api.tasklist.TaskListServiceI;
import com.zcloud.safetyDutyList.dto.clientobject.tasklist.TaskExecutionCO;
import com.zcloud.safetyDutyList.dto.tasklist.TaskDetailUpdateScoreCmd;
import com.zcloud.safetyDutyList.dto.tasklist.TaskExecutionCloseCmd;
import com.zcloud.safetyDutyList.dto.tasklist.TaskExecutionPageQry;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 任务执行记录控制器
 * <p>
 * 提供任务执行记录的查询接口，
 * 委托TaskListServiceI处理业务逻辑。
 */
@Api(tags = "任务执行记录")
@RequestMapping("/${application.gateway}/taskExecution")
@RestController
@AllArgsConstructor
public class TaskExecutionController {
    private final TaskListServiceI taskListService;

    @ApiOperation("获取任务执行记录列表")
    @PostMapping("/list")
    public PageResponse<TaskExecutionCO> listPage(@Validated @RequestBody TaskExecutionPageQry qry) {
        return taskListService.listExecutionPage(qry);
    }

    @ApiOperation("获取任务执行记录详情")
    @GetMapping("/{taskExecutionId}")
    public SingleResponse<TaskExecutionCO> getByTaskExecutionId(@PathVariable String taskExecutionId) {
        return taskListService.getExecutionByTaskExecutionId(taskExecutionId);
    }

    @ApiOperation("更新任务评分")
    @PostMapping("/updateScore")
    public Response updateScore(@Validated @RequestBody TaskDetailUpdateScoreCmd cmd) {
        return taskListService.updateTaskDetailScore(cmd);
    }

    @ApiOperation("关闭任务")
    @PostMapping("/close")
    public Response close(@Validated @RequestBody TaskExecutionCloseCmd cmd) {
        return taskListService.closeTaskExecution(cmd);
    }
}
