"use client";

import ReportEngine, { ReportConfig } from "@/components/admin/report/ReportEngine";

const config: ReportConfig = {
  key: "equipment_report_v2",
  title: "설비 리포트",
  description: "설비 가동/보전 다중 조건 비교 분석",
  apiEndpoint: "/report/equipment/data",
  metrics: [
    { id: "runTime", name: "가동시간", unit: "H", color: "#3b82f6" },
    { id: "downTime", name: "비가동시간", unit: "H", color: "#ef4444" },
    { id: "opRate", name: "가동률", unit: "%", color: "#10b981", isRate: true },
    { id: "faultCnt", name: "고장횟수", unit: "회", color: "#f59e0b" },
    { id: "mtbf", name: "MTBF", unit: "H", color: "#8b5cf6" },
    { id: "mttr", name: "MTTR", unit: "H", color: "#ec4899" },
    { id: "maintCost", name: "보전비용", unit: "만원", color: "#06b6d4" },
    { id: "prodQty", name: "생산수량", unit: "EA", color: "#84cc16" },
  ],
  groupByOptions: [
    { id: "equipment", name: "설비별" },
    { id: "equipType", name: "설비유형별" },
    { id: "line", name: "라인별" },
    { id: "manager", name: "담당자별" },
    { id: "monthly", name: "월별" },
    { id: "quarterly", name: "분기별" },
    { id: "weekly", name: "주별" },
    { id: "daily", name: "일별" },
  ],
  defaultGroupBy: "equipment",
  defaultMetrics: ["runTime"],
  thresholds: [
    { id: "fault", label: "고장횟수 ≥", defaultValue: 3, unit: "회" },
    { id: "opRate", label: "가동률 ≤", defaultValue: 80, unit: "%" },
  ],
  filterFieldDefs: [
    { id: "equipment", name: "설비", type: "select", optionKey: "equipment" },
    { id: "equipType", name: "설비유형", type: "select", optionKey: "equipTypes" },
    { id: "line", name: "라인", type: "select", optionKey: "lines" },
    { id: "manager", name: "담당자", type: "select", optionKey: "managers" },
    { id: "opRate", name: "가동률", type: "number" },
    { id: "faultCnt", name: "고장횟수", type: "number" },
  ],
  drilldownColumns: [
    { id: "date", name: "날짜", format: "date" },
    { id: "equipment", name: "설비" },
    { id: "equipType", name: "설비유형" },
    { id: "line", name: "라인" },
    { id: "status", name: "상태", format: "badge" },
    { id: "runTime", name: "가동시간", align: "right", format: "number" },
    { id: "downTime", name: "비가동시간", align: "right", format: "number" },
    { id: "opRate", name: "가동률(%)", align: "right", format: "number" },
    { id: "faultCnt", name: "고장횟수", align: "right", format: "number" },
  ],
  rawDataColumns: [
    { id: "date", name: "날짜", format: "date" },
    { id: "equipment_code", name: "설비코드" },
    { id: "equipment", name: "설비명" },
    { id: "equipType", name: "설비유형" },
    { id: "line", name: "라인" },
    { id: "manager", name: "담당자" },
    { id: "status", name: "상태", format: "badge" },
    { id: "runTime", name: "가동시간", align: "right", format: "number" },
    { id: "downTime", name: "비가동시간", align: "right", format: "number" },
    { id: "faultCnt", name: "고장횟수", align: "right", format: "number" },
  ],
  emptyMessage: "설비 데이터가 없습니다",
};

export default function EquipmentReportPage() {
  return <ReportEngine config={config} />;
}
