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

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.task.vo.mytask.MyTaskPageReqVO;
import com.njcn.rdms.module.project.controller.admin.project.task.vo.mytask.MyTaskRespVO;
import com.njcn.rdms.module.project.service.project.task.MyTaskService;
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/tasks")
@Validated
public class MyTaskController {

    @Resource
    private MyTaskService myTaskService;

    @GetMapping("/page")
    @Operation(summary = "分页获取当前登录用户负责或协办的非终态任务(跨项目)")
    public CommonResult<PageResult<MyTaskRespVO>> getMyTaskPage(@Valid MyTaskPageReqVO reqVO) {
        // 前端固定传 pageSize=-1 拉全部；负数统一归一为 PAGE_SIZE_NONE，与 me 系列一致
        if (reqVO.getPageSize() != null && reqVO.getPageSize() < 0) {
            reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        }
        return success(myTaskService.getMyTaskPage(reqVO));
    }

}
