package com.zioinfo.kintex.dashboard;

import com.zioinfo.kintex.auth.EventAccessGuard;
import com.zioinfo.kintex.auth.KintexPrincipal;
import com.zioinfo.kintex.common.ApiResponse;
import com.zioinfo.kintex.dashboard.dto.DashboardDto;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 주최자 대시보드 API (SCR-02). 행사 멤버/홀매니저 열람.
 */
@RestController
@RequestMapping("/api/events/{eventId}/dashboard")
public class DashboardController {

    private final DashboardService service;
    private final EventAccessGuard guard;

    public DashboardController(DashboardService service, EventAccessGuard guard) {
        this.service = service;
        this.guard = guard;
    }

    /** GET — 마일스톤·KPI·참가업체·활동 피드 집계. */
    @GetMapping
    public ApiResponse<DashboardDto> get(@AuthenticationPrincipal KintexPrincipal principal,
                                         @PathVariable String eventId) {
        guard.requireEventAccess(principal, eventId);
        return ApiResponse.ok(service.getDashboard(eventId));
    }
}
