package com.chinaweal.aiccs.aiccs.force.cancel.controller;

import com.chinaweal.aiccs.aiccs.force.cancel.entity.dto.CancelRevokeApproveDTO;
import com.chinaweal.aiccs.aiccs.force.cancel.entity.dto.CancelRevokeCreateDTO;
import com.chinaweal.aiccs.aiccs.force.cancel.entity.dto.CancelRevokeQueryDTO;
import com.chinaweal.aiccs.aiccs.force.cancel.entity.vo.*;
import com.chinaweal.aiccs.aiccs.force.cancel.service.ICancelRevokeService;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 撤销吊销Controller
 */
@Api(tags = "撤销吊销管理")
@RestController
@RequestMapping("/api/cancelRevoke")
public class CancelRevokeController extends BaseController {

    @Autowired
    private ICancelRevokeService cancelRevokeService;

    /**
     * 查询吊销主体列表（个案办理选择）
     * GET /api/cancelRevoke/revokedList
     */
    @ApiOperation("查询吊销主体列表")
    @GetMapping("/revokedList")
    public RestResult<CancelRevokePageVO> getRevokedList(CancelRevokeQueryDTO queryDTO) {
        CancelRevokePageVO result = cancelRevokeService.queryRevokedEntList(queryDTO);
        return RestResult.ok(result);
    }

    /**
     * 发起撤销吊销业务
     * POST /api/cancelRevoke
     */
    @ApiOperation("发起撤销吊销业务")
    @PostMapping
    public RestResult<CancelRevokeCreateVO> createCancelRevoke(
            @Validated @RequestBody CancelRevokeCreateDTO createDTO,
            HttpServletRequest request) {
        CancelRevokeCreateVO result = cancelRevokeService.createCancelRevoke(createDTO, request);
        return RestResult.ok(result);
    }

    /**
     * 查询撤销吊销业务详情
     * GET /api/cancelRevoke/{bizId}
     */
    @ApiOperation("查询撤销吊销业务详情")
    @GetMapping("/{bizId}")
    public RestResult<CancelRevokeVO> getCancelRevokeById(
            @ApiParam("业务ID") @PathVariable String bizId,
            @ApiParam("任务ID") @RequestParam(required = false) String tasklistid) {
        CancelRevokeVO vo = cancelRevokeService.getCancelRevokeById(bizId, tasklistid);
        return RestResult.ok(vo);
    }

    /**
     * 分页查询撤销吊销业务列表（撤销吊销记录）
     * GET /api/cancelRevoke/records
     */
    @ApiOperation("分页查询撤销吊销业务记录")
    @GetMapping("/records")
    public RestResult<CancelRevokePageVO> getCancelRevokeRecords(CancelRevokeQueryDTO queryDTO) {
        CancelRevokePageVO result = cancelRevokeService.queryCancelRevokeRecords(queryDTO);
        return RestResult.ok(result);
    }

    /**
     * 分页查询待审批列表
     * GET /api/cancelRevoke/approveList
     */
    @ApiOperation("分页查询待审批列表")
    @GetMapping("/approveList")
    public RestResult<CancelRevokePageVO> getApproveList(CancelRevokeQueryDTO queryDTO) {
        CancelRevokePageVO result = cancelRevokeService.queryApproveList(queryDTO);
        return RestResult.ok(result);
    }

//    /**
//     * 审批操作
//     * POST /api/cancelRevoke/approve
//     */
//    @ApiOperation("审批操作")
//    @PostMapping("/approve")
//    public RestResult<CancelRevokeApproveResultVO> approve(
//            @Validated @RequestBody CancelRevokeApproveDTO approveDTO,
//            HttpServletRequest request) {
//        CancelRevokeApproveResultVO result = cancelRevokeService.approve(approveDTO, request);
//        return RestResult.ok(result);
//    }

    /**
     * 撤销吊销待办列表（我的待办）
     * GET /api/cancelRevoke/todoList
     */
    @ApiOperation("撤销吊销待办列表")
    @GetMapping("/todoList")
    public RestResult<CancelRevokePageVO> getTodoList(CancelRevokeQueryDTO queryDTO, HttpServletRequest request) {
        CancelRevokePageVO result = cancelRevokeService.queryTodoList(queryDTO, request);
        return RestResult.ok(result);
    }

    /**
     * 启动流程下一步
     * POST /api/cancelRevoke/next
     */
    @ApiOperation("启动流程下一步")
    @PostMapping("/next")
    public RestResult<CancelRevokeApproveResultVO> approvalNext(
            @RequestBody CancelRevokeApproveDTO approveDTO,
            HttpServletRequest request) {
        CancelRevokeApproveResultVO result = cancelRevokeService.approve(approveDTO, request);
        return RestResult.ok(result);
    }

    /**
     * 查询业务详情（带工作流信息）
     * GET /api/cancelRevoke/detail/{bizSeq}
     */
    @ApiOperation("查询业务详情")
    @GetMapping("/detail/{bizSeq}")
    public RestResult<CancelRevokeVO> getCancelRevokeDetail(
            @ApiParam("业务编号") @PathVariable String bizSeq,
            @ApiParam("任务ID") @RequestParam(required = false) String tasklistid) {
        CancelRevokeVO vo = cancelRevokeService.getCancelRevokeDetail(bizSeq, tasklistid);
        return RestResult.ok(vo);
    }
}
