/*
 * 경영분석 대시보드 표시 데이터 (SCR-13 · M16 BI).
 * ★ 경계면: M16 BI 데이터마트(FactBooking·FactSettlement·FactUtility·FactAuction·FactVisitor + Dim*)와
 *   KpiSnapshot 집계 파이프라인은 DA 후속 트랙 미구축(PLANNING §5A M16-1).
 *   따라서 KPI·추세·RevPAD·리텐션·P&L·매칭 지표는 전부 샘플 시연이다.
 *   원천(행사·부스·정산 레코드)은 실 API 부분 가능하나 BI 집계 API 부재 → 샘플.
 */
import type { FlowStatus } from '../../components/ui/Badge';

export type Perspective = 'operator' | 'exhibitor';
export type Period = 'event' | 'd90' | 'annual';

export interface Kpi {
  key: string;
  label: string;
  value: string;
  delta?: string; // "+4%p"
  deltaDir?: 'up' | 'down';
  tone?: 'normal' | 'warn' | 'error';
  ai?: boolean;
}

/** 매출 구성 추이 — 다계열 + 마지막 2점은 AI 예측(forecast=true). */
export interface TrendPoint {
  label: string;
  rental: number; // 임대(백만)
  utility: number; // 유틸리티(백만)
  auction: number; // 옥션 수수료(백만)
  forecast?: boolean;
}
export interface ExhibitorTrendPoint {
  label: string;
  exhibitors: number; // 참가업체 매칭 요청
  buyers: number; // 바이어 매칭
  forecast?: boolean;
}

export interface SectorRow {
  label: string;
  pct: number;
}

export interface PnlRow {
  event: string;
  hall: string;
  revenue: string;
  contribution: string;
  margin: string;
  grade: 'excellent' | 'good' | 'fair' | 'review';
}
export interface ExhibitorPerfRow {
  company: string;
  booth: string;
  visits: number;
  matches: number;
  status: FlowStatus;
  grade: 'excellent' | 'good' | 'fair' | 'review';
}

export const GRADE_LABEL: Record<PnlRow['grade'], string> = {
  excellent: '우수',
  good: '양호',
  fair: '보통',
  review: '검토필요',
};

// ── 운영사 관점 ──
export const OPERATOR_KPIS: Kpi[] = [
  { key: 'occ', label: '홀 가동률', value: '78%', delta: '+4%p', deltaDir: 'up' },
  { key: 'rev', label: '매출 (임대+유틸+옥션)', value: '₩1.24B', delta: '+12.5%', deltaDir: 'up' },
  { key: 'revpad', label: '㎡당 수익 (RevPAD)', value: '₩58,200', delta: '+3.1%', deltaDir: 'up' },
  { key: 'ret', label: '참가사 리텐션(재참가)', value: '81%', delta: '-2%p', deltaDir: 'down', tone: 'warn' },
];

export const OPERATOR_TREND: TrendPoint[] = [
  { label: '4월', rental: 620, utility: 140, auction: 55 },
  { label: '5월', rental: 680, utility: 155, auction: 62 },
  { label: '6월', rental: 720, utility: 168, auction: 70 },
  { label: '7월', rental: 790, utility: 182, auction: 78 },
  { label: '8월', rental: 860, utility: 205, auction: 88 },
  { label: '9월(예측)', rental: 910, utility: 220, auction: 95, forecast: true },
  { label: '10월(예측)', rental: 965, utility: 236, auction: 102, forecast: true },
];

export const OPERATOR_PNL: PnlRow[] = [
  { event: '스마트팩토리 코리아', hall: '홀 4·5', revenue: '₩412M', contribution: '₩168M', margin: '40.8%', grade: 'excellent' },
  { event: '국제 헬스케어 위크', hall: '홀 7', revenue: '₩286M', contribution: '₩101M', margin: '35.3%', grade: 'good' },
  { event: '푸드테크 엑스포', hall: '홀 3', revenue: '₩198M', contribution: '₩52M', margin: '26.3%', grade: 'fair' },
  { event: '리빙·인테리어 페어', hall: '홀 1·2', revenue: '₩344M', contribution: '₩58M', margin: '16.9%', grade: 'review' },
];

// ── 참가업체 관점 ──
export const EXHIBITOR_KPIS: Kpi[] = [
  { key: 'visit', label: '총 방문 (부스)', value: '3,420', delta: '+18%', deltaDir: 'up' },
  { key: 'stay', label: '평균 체류시간', value: '7분 20초', delta: '+42초', deltaDir: 'up' },
  { key: 'match', label: '매칭 성공률', value: '34%', delta: '+6%p', deltaDir: 'up', ai: true },
  { key: 'roi', label: '부스 비용 대비 리드', value: '₩38k/리드', delta: '-9%', deltaDir: 'down', tone: 'warn' },
];

export const EXHIBITOR_TREND: ExhibitorTrendPoint[] = [
  { label: 'D-4', exhibitors: 80, buyers: 42 },
  { label: 'D-3', exhibitors: 130, buyers: 76 },
  { label: 'D-2', exhibitors: 205, buyers: 128 },
  { label: 'D-1', exhibitors: 260, buyers: 172 },
  { label: '개장일', exhibitors: 340, buyers: 240 },
  { label: 'D+1(예측)', exhibitors: 390, buyers: 285, forecast: true },
  { label: 'D+2(예측)', exhibitors: 430, buyers: 320, forecast: true },
];

export const EXHIBITOR_PERF: ExhibitorPerfRow[] = [
  { company: '(주)한빛로보틱스', booth: 'A-102', visits: 512, matches: 88, status: 'approved', grade: 'excellent' },
  { company: '누리테크놀로지', booth: 'B-201', visits: 388, matches: 61, status: 'approved', grade: 'good' },
  { company: '대성정밀', booth: 'A-104', visits: 246, matches: 32, status: 'ai-review', grade: 'fair' },
  { company: '세종머신', booth: 'B-205', visits: 118, matches: 9, status: 'rejected', grade: 'review' },
];

// 업종별 구성(공통) — 가로 막대.
export const SECTORS: SectorRow[] = [
  { label: '기술·IT', pct: 45 },
  { label: '제조', pct: 28 },
  { label: '헬스케어', pct: 15 },
  { label: '유통', pct: 12 },
];
