package com.qmth.sop.server.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.bean.result.ProjectMonitorCardResult;
import com.qmth.sop.business.bean.result.ProjectMonitorResult;
import com.qmth.sop.business.service.ProjectMonitorService;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.CrmProcessEnum;
import com.qmth.sop.common.util.Result;
import com.qmth.sop.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * @Description 项目监控
 * @Author haoguanghui
 * @date 2024/09/04
 */
@Api(tags = "项目监控Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_PROJECT_MONITOR)
public class ProjectMonitorController {

    @Resource
    ProjectMonitorService projectMonitorService;

    @ApiOperation(value = "项目监控分页")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "项目监控分页", response = ProjectMonitorResult.class) })
    public Result page(
            @ApiParam(value = "服务单元ID", required = false) @RequestParam(required = false) Long serviceUnitId,
            @ApiParam(value = "客户ID", required = false) @RequestParam(required = false) Long customerId,
            @ApiParam(value = "项目进度", required = false) @RequestParam(required = false) CrmProcessEnum process,
            @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
            @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        return ResultUtil.ok(projectMonitorService.pageProjectMonitor(new Page<>(pageNumber, pageSize), serviceUnitId, customerId, process));
    }

    @ApiOperation(value = "工作证")
    @RequestMapping(value = "/user/detail", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "工作证", response = ProjectMonitorCardResult.class) })
    public Result userCard(@ApiParam(value = "用户ID", required = true) @RequestParam(required = true) Long userId) {
        return ResultUtil.ok(projectMonitorService.getUserCard(userId));
    }

}
