package com.zioinfo.mall.uiws.stats.controller;

import com.zioinfo.mall.common.ApiResponse;
import com.zioinfo.mall.uiws.stats.dto.StatsDtos.PivotResponse;
import com.zioinfo.mall.uiws.stats.service.StatsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * UIWS 이식 — 업무통계(모듈 04, 동적 컬럼 피벗). 인증 필수(/api/stats).
 * prefix /api/stats 는 ERP 기존 라우트와 미충돌(확인). 원본 엔드포인트 보존.
 */
@Tag(name = "UIWS-업무통계", description = "UIWS 이식: 근무현황 동적 피벗")
@RestController
@RequestMapping("/api/stats")
@RequiredArgsConstructor
public class StatsController {

    private final StatsService statsService;

    @Operation(summary = "개인별 근무현황(행=근무자×상태×유형, 동적열=근무처)")
    @GetMapping("/personal-work")
    public ApiResponse<PivotResponse> personalWork(
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDate,
            @RequestParam(required = false) String deptId,
            @RequestParam(required = false) String userId,
            @RequestParam(required = false) Boolean showStatus,
            @RequestParam(required = false) Boolean showType) {
        return ApiResponse.ok(statsService.personalWork(fromDate, toDate, deptId, userId, showStatus, showType));
    }

    @Operation(summary = "업체별 근무현황(행=근무처×유형, 동적열=근무자)")
    @GetMapping("/company-work")
    public ApiResponse<PivotResponse> companyWork(
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDate,
            @RequestParam(required = false) String companyId,
            @RequestParam(required = false) String userId,
            @RequestParam(required = false) Boolean showType) {
        return ApiResponse.ok(statsService.companyWork(fromDate, toDate, companyId, userId, showType));
    }
}
