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.TaskListCO;
import com.zcloud.safetyDutyList.dto.clientobject.tasklist.TaskListIssueCO;
import com.zcloud.safetyDutyList.dto.tasklist.*;
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}/taskList")
@RestController
@AllArgsConstructor
public class TaskListController {
    /** 安全责任清单服务接口 */
    private final TaskListServiceI taskListService;

    @ApiOperation("获取任务清单列表")
    @PostMapping("/list")
    public PageResponse<TaskListCO> listPage(@RequestBody TaskListPageQry qry) {
        return taskListService.listPage(qry);
    }

    @ApiOperation("新增任务清单")
    @PostMapping("/save")
    public SingleResponse<TaskListCO> add(@Validated @RequestBody TaskListAddCmd cmd) {
        return taskListService.add(cmd);
    }

    @ApiOperation("修改任务清单")
    @PostMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody TaskListUpdateCmd cmd) {
        return taskListService.edit(cmd);
    }

    @ApiOperation("删除任务清单")
    @PostMapping("/delete/{id}")
    public Response remove(@PathVariable Long id) {
        return taskListService.remove(id);
    }

    @ApiOperation("开启/关闭任务清单 - 只有关闭，调此接口就说明要关闭任务清单")
    @PostMapping("/switchFlag")
    public SingleResponse switchFlag(@Validated @RequestBody TaskListSwitchCmd cmd) {
        return taskListService.switchFlag(cmd);
    }

    @ApiOperation("任务下发")
    @PostMapping("/issue")
    public SingleResponse issue(@Validated @RequestBody TaskListIssueCmd cmd) {
        return taskListService.issue(cmd);
    }
}
