package com.zioinfo.kintex.admin;

import com.zioinfo.kintex.admin.dto.AdminDashboardDto;
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-14). 시스템관리자(홀매니저/ADMIN)만 접근.
 */
@RestController
@RequestMapping("/api/admin/dashboard")
public class AdminDashboardController {

    private final AdminDashboardService service;
    private final SystemAccessGuard guard;

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

    /** GET — 전 행사 KPI·라이브 행사·(원천 있으면)관람객 추이. */
    @GetMapping
    public ApiResponse<AdminDashboardDto> get(@AuthenticationPrincipal KintexPrincipal principal,
                                              @RequestParam(required = false, defaultValue = "KINTEX") String tenant) {
        guard.requireAdmin(principal);
        return ApiResponse.ok(service.getDashboard(tenant));
    }
}
