package com.njcn.gather.aireport.reportapproval.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.gather.aireport.reportapproval.pojo.param.ReportApprovalParam;
import com.njcn.gather.aireport.reportapproval.pojo.vo.ReportApprovalLogVO;
import com.njcn.gather.aireport.reportapproval.pojo.vo.ReportApprovalPendingVO;
import com.njcn.gather.aireport.reportapproval.service.ReportApprovalService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "报告审批管理")
@RestController
@RequestMapping("/api/report-approval")
@RequiredArgsConstructor
public class ReportApprovalController extends BaseController {

    private final ReportApprovalService reportApprovalService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询待审报告分页")
    @GetMapping("/pending-page")
    public HttpResult<Page<ReportApprovalPendingVO>> pendingPage(@ModelAttribute ReportApprovalParam.PendingQueryParam param) {
        String methodDescribe = getMethodDescribe("pendingPage");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,
                reportApprovalService.pendingPage(param), methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @ApiOperation("审批通过")
    @PostMapping("/pass")
    public HttpResult<Boolean> pass(@RequestBody @Validated ReportApprovalParam.AuditParam param) {
        String methodDescribe = getMethodDescribe("pass");
        boolean result = reportApprovalService.pass(param);
        return HttpResultUtil.assembleCommonResponseResult(result ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL,
                result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @ApiOperation("审批退回")
    @PostMapping("/reject")
    public HttpResult<Boolean> reject(@RequestBody @Validated ReportApprovalParam.AuditParam param) {
        String methodDescribe = getMethodDescribe("reject");
        boolean result = reportApprovalService.reject(param);
        return HttpResultUtil.assembleCommonResponseResult(result ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL,
                result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询审批日志分页")
    @GetMapping("/log-page")
    public HttpResult<Page<ReportApprovalLogVO>> logPage(@ModelAttribute ReportApprovalParam.LogQueryParam param) {
        String methodDescribe = getMethodDescribe("logPage");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,
                reportApprovalService.logPage(param), methodDescribe);
    }
}
