package com.zioinfo.kintex.work.stats;

import com.zioinfo.kintex.auth.EventAccessGuard;
import com.zioinfo.kintex.auth.KintexPrincipal;
import com.zioinfo.kintex.common.ApiResponse;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

/** 업무 통계 API (/api/work/stats). 인증 사용자. DataScope는 서비스에서 적용. */
@RestController
@RequestMapping("/api/work/stats")
public class StatsController {

    private final StatsService service;
    private final EventAccessGuard guard;

    public StatsController(StatsService service, EventAccessGuard guard) {
        this.service = service;
        this.guard = guard;
    }

    @GetMapping("/worklog")
    public ApiResponse<WorkStatsDto> worklog(@AuthenticationPrincipal KintexPrincipal principal,
                                             @RequestParam(required = false) String eventId,
                                             @RequestParam(required = false) String fromDate,
                                             @RequestParam(required = false) String toDate) {
        guard.require(principal);
        return ApiResponse.ok(service.workStats(principal, eventId, fromDate, toDate));
    }
}
