package com.njcn.rdms.module.project.controller.admin.project.execution;

import com.njcn.rdms.framework.common.pojo.CommonResult;
import com.njcn.rdms.framework.common.pojo.PageParam;
import com.njcn.rdms.framework.common.pojo.PageResult;
import com.njcn.rdms.module.project.controller.admin.project.execution.vo.execution.MyProjectExecutionPageReqVO;
import com.njcn.rdms.module.project.controller.admin.project.execution.vo.execution.MyProjectExecutionRespVO;
import com.njcn.rdms.module.project.service.project.execution.ProjectExecutionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.njcn.rdms.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 我负责的执行（跨项目）")
@RestController
@RequestMapping("/project/project/me/executions")
@Validated
public class MyExecutionController {

    @Resource
    private ProjectExecutionService projectExecutionService;

    @GetMapping("/page")
    @Operation(summary = "分页获取当前登录用户负责的执行（跨项目，默认排除终态与进度满）")
    public CommonResult<PageResult<MyProjectExecutionRespVO>> getMyExecutionPage(@Valid MyProjectExecutionPageReqVO reqVO) {
        // 前端固定传 pageSize=-1 拉全部；负数统一归一为 PAGE_SIZE_NONE(-1)，与现有执行分页接口一致
        if (reqVO.getPageSize() != null && reqVO.getPageSize() < 0) {
            reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        }
        return success(projectExecutionService.getMyExecutionPage(reqVO));
    }

}
