package com.xdap.self_development.controller;


import com.definesys.mpaas.common.http.Response;
import com.xdap.self_development.controller.request.RejectTodoRequest;
import com.xdap.self_development.controller.request.TodoTaskRequest;
import com.xdap.self_development.domain.dto.EngineParamDetailDTO;
import com.xdap.self_development.domain.dto.PageResultDTO;
import com.xdap.self_development.domain.pojo.CompletedTaskPojo;
import com.xdap.self_development.domain.pojo.InitiatedTaskPojo;
import com.xdap.self_development.domain.pojo.TodoTaskPojo;
import com.xdap.self_development.service.TodoTaskService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 待办任务控制器
 * 提供待办任务相关的功能，包括查询发起的待办、用户待办、用户已办、创建责任人、退回单据等
 *
 * @version 1.0
 * @since 2025
 */
@RestController
@RequestMapping("/custom/todoTaskPojo")
public class TodoTaskController {
    @Resource
    private TodoTaskService todoTaskService;
    /**
     * 查询发起的待办
     *
     * @param todoTaskRequest 待办任务请求
     * @return 发起的待办分页结果
     */
    @PostMapping("/selectByPageByCreate")
    public Response selectByPageByCreate(@RequestBody TodoTaskRequest todoTaskRequest){
        PageResultDTO<InitiatedTaskPojo> page=  todoTaskService.selectByPage(todoTaskRequest);
       return Response.ok().data(page);
    }
    /**
     * 查询用户待办
     *
     * @param todoTaskRequest 待办任务请求
     * @return 用户待办分页结果
     */
    @PostMapping("/selectByresPersonTodoPage")
    public Response selectByresPersonTodoPage(@RequestBody TodoTaskRequest todoTaskRequest){
        PageResultDTO<TodoTaskPojo> todoTaskPojos =  todoTaskService.selectByresPersonTodoPage(todoTaskRequest);
        return Response.ok().data(todoTaskPojos);
    }
    /**
     * 查询用户已办
     *
     * @param todoTaskRequest 待办任务请求
     * @return 用户已办分页结果
     */
    @PostMapping("/selectByresPersonCompletedPage")
    public Response selectByresPersonCompletedPage(@RequestBody TodoTaskRequest todoTaskRequest){
        PageResultDTO<CompletedTaskPojo> todoTaskPojos =  todoTaskService.selectByresPersonCompletedPage(todoTaskRequest);
        return Response.ok().data(todoTaskPojos);
    }
    /**
     * 通过管理员或分解待办任务创建责任人
     *
     * @param paramDetailPojos 参数详情列表
     * @param userID          用户ID
     * @return 操作结果响应
     */
    @PostMapping("/createResPerson")
    public Response createResPerson(
            @RequestBody List<EngineParamDetailDTO> paramDetailPojos,
            @RequestParam String userID
    ) {
        todoTaskService.createResPerson(paramDetailPojos,userID);
        return Response.ok();

    }
    /**
     * 退回单据
     *
     * @param request 待办退回请求
     * @return 操作结果响应
     */
    @PostMapping("/rejectTodo")
    public Response todoReturn(@RequestBody RejectTodoRequest request) {
        todoTaskService.rejectTodo(request);
        return Response.ok();

    }

    /**
     * 跳过审批
     *
     * @param todoTaskRequest
     * @return
     */
    @PostMapping("/skipApproval")
    public Response skipApproval(@RequestBody RejectTodoRequest todoTaskRequest) {
        todoTaskService.skipApproval(todoTaskRequest);
        return Response.ok();
    }

}

