package com.zioinfo.kintex.admin;

import com.zioinfo.kintex.admin.dto.AdminStatsDto;
import com.zioinfo.kintex.auth.KintexPrincipal;
import com.zioinfo.kintex.common.ApiResponse;
import com.zioinfo.kintex.system.SystemAccessGuard;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
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;

/**
 * 관리자 집계 지표 API (SCR-16 실전환 · UNDEVELOPED_BACKLOG §1).
 * 시스템관리자(홀매니저/ADMIN)만 접근 — 대시보드 컨트롤러와 동일 가드(SystemAccessGuard.requireAdmin).
 * 실 테이블 존재분(사용자·행사·테넌트·등록업체·오늘 체크인)만 집계. 실시간 방문객·주차·라이브는 미포함.
 */
@RestController
@RequestMapping("/api/admin/stats")
public class AdminStatsController {

    private final AdminDashboardService service;
    private final SystemAccessGuard guard;

    public AdminStatsController(AdminDashboardService service, SystemAccessGuard guard) {
        this.service = service;
        this.guard = guard;
    }

    /** GET — 실 집계 가능한 관리자 지표(개수만, 자격증명·PII 미포함). */
    @GetMapping
    public ApiResponse<AdminStatsDto> get(@AuthenticationPrincipal KintexPrincipal principal,
                                          @RequestParam(required = false, defaultValue = "KINTEX") String tenant) {
        guard.requireAdmin(principal);
        return ApiResponse.ok(service.getStats(tenant));
    }
}
