/*
 * SCR-13 경영분석 — 테넌트 전역(행사 횡단) BI 로컬 API.
 * 백엔드 GET /api/analytics/overview?years=N (com.zioinfo.kintex.analytics.AnalyticsOverviewController).
 * 홀매니저 전용. 공용 api/{client,endpoints,types}는 수정하지 않고 client의 `api`만 재사용한다.
 * 계약 shape = AnalyticsOverviewDto(백엔드).
 */
import { api } from '../../api/client';

export interface OverviewKpi {
  label: string;
  value: string;
  hint: string | null;
}

export interface EventRevenue {
  eventId: string;
  eventName: string;
  revenue: number;
  boothCount: number;
  areaM2: number;
  grade: 'A' | 'B' | 'C' | string;
}

export interface OccupancyPoint {
  period: string; // "YYYY-MM"
  occupancyPercent: number;
  bookedDays: number;
  capacityDays: number;
}

export interface RetentionYear {
  period: string; // "YYYY"
  companies: number;
  returningCompanies: number;
  retentionPercent: number;
}

export interface Retention {
  totalCompanies: number;
  returningCompanies: number;
  retentionPercent: number;
  byYear: RetentionYear[];
}

export interface ForecastPoint {
  period: string; // "YYYY"
  value: number;
  projected: boolean;
}

export interface Forecast {
  metric: string;
  method: string;
  history: ForecastPoint[];
  projection: ForecastPoint[];
}

export interface AnalyticsOverview {
  kpis: OverviewKpi[];
  eventComparison: EventRevenue[];
  hallOccupancy: OccupancyPoint[];
  retention: Retention;
  forecast: Forecast;
}

export const analyticsOverviewApi = {
  get: (years = 5) =>
    api.get<AnalyticsOverview>(`/api/analytics/overview?years=${encodeURIComponent(years)}`),
};
