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

import com.njcn.rdms.framework.common.pojo.CommonResult;
import com.njcn.rdms.module.project.controller.admin.project.project.vo.workbench.MyWorklogWeekRespVO;
import com.njcn.rdms.module.project.controller.admin.project.project.vo.workbench.TeamLoadRespVO;
import com.njcn.rdms.module.project.controller.admin.project.project.vo.workbench.TeamWorklogWeekRespVO;
import com.njcn.rdms.module.project.service.project.MyTeamService;
import com.njcn.rdms.module.project.service.project.MyWorklogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.springframework.format.annotation.DateTimeFormat;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

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

@Tag(name = "管理后台 - 工作台统计(团队负载/工时周聚合)")
@RestController
@RequestMapping("/project/project/me")
@Validated
public class MyWorkbenchController {

    @Resource
    private MyTeamService myTeamService;
    @Resource
    private MyWorklogService myWorklogService;

    @GetMapping("/team-load")
    @Operation(summary = "团队负载统计(团队=自己+管理链路当前生效直接下级)")
    public CommonResult<TeamLoadRespVO> getTeamLoad() {
        return success(myTeamService.getTeamLoad());
    }

    @GetMapping("/worklog-week")
    @Operation(summary = "我的工时周聚合(返回周一~周日;按周填报只均摊到工作日,周末单天工时保留在周末)")
    public CommonResult<MyWorklogWeekRespVO> getMyWorklogWeek(
            @RequestParam("weekStart")
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @NotNull(message = "weekStart 不能为空") LocalDate weekStart) {
        return success(myWorklogService.getMyWorklogWeek(weekStart));
    }

    @GetMapping("/team-worklog-week")
    @Operation(summary = "团队工时周聚合(成员集合与 team-load 同口径)")
    public CommonResult<TeamWorklogWeekRespVO> getTeamWorklogWeek(
            @RequestParam("weekStart")
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @NotNull(message = "weekStart 不能为空") LocalDate weekStart) {
        return success(myWorklogService.getTeamWorklogWeek(weekStart));
    }

}
