/**
 * 작업실적 조회 Mock 데이터
 */

import type { WorkResult, WorkResultStats } from './types';

// Mock 작업실적 데이터
export const mockWorkResults: WorkResult[] = [
  {
    id: 'wr-1',
    lotNo: 'KD-TS-250212-01-01',
    workDate: '2025-02-12',
    workOrderNo: 'KD-PL-250122-01',
    processType: 'screen',
    productName: '스크린 셔터 (프리미엄)',
    specification: '8000x2800',
    productionQty: 1,
    goodQty: 0,
    defectQty: 1,
    defectRate: 100.0,
    inspection: true,
    packaging: false,
    worker: '이성산',
  },
  {
    id: 'wr-2',
    lotNo: 'KD-TS-250210-01-02',
    workDate: '2025-02-10',
    workOrderNo: 'KD-PL-250120-01',
    processType: 'screen',
    productName: '스크린 셔터 (표준형)',
    specification: '6500x2400',
    productionQty: 1,
    goodQty: 1,
    defectQty: 0,
    defectRate: 0.0,
    inspection: true,
    packaging: true,
    worker: '김성산',
  },
  {
    id: 'wr-3',
    lotNo: 'KD-TS-250210-01-01',
    workDate: '2025-02-10',
    workOrderNo: 'KD-PL-250120-01',
    processType: 'screen',
    productName: '스크린 셔터 (표준형)',
    specification: '7660x2550',
    productionQty: 1,
    goodQty: 1,
    defectQty: 0,
    defectRate: 0.0,
    inspection: true,
    packaging: true,
    worker: '김성산',
  },
  {
    id: 'wr-4',
    lotNo: 'KD-TS-250208-01-01',
    workDate: '2025-02-08',
    workOrderNo: 'KD-PL-250118-01',
    processType: 'slat',
    productName: '철재 슬랫 셔터',
    specification: '5000x3000',
    productionQty: 2,
    goodQty: 2,
    defectQty: 0,
    defectRate: 0.0,
    inspection: true,
    packaging: true,
    worker: '박철호',
  },
  {
    id: 'wr-5',
    lotNo: 'KD-TS-250205-01-01',
    workDate: '2025-02-05',
    workOrderNo: 'KD-PL-250115-01',
    processType: 'bending',
    productName: '방화셔터 절곡 부품 SET',
    specification: '3000x4000',
    productionQty: 3,
    goodQty: 2,
    defectQty: 1,
    defectRate: 33.3,
    inspection: true,
    packaging: true,
    worker: '최절곡',
  },
  {
    id: 'wr-6',
    lotNo: 'KD-TS-250203-01-01',
    workDate: '2025-02-03',
    workOrderNo: 'KD-PL-250113-01',
    processType: 'screen',
    productName: '스크린 셔터 (프리미엄)',
    specification: '9000x3200',
    productionQty: 1,
    goodQty: 1,
    defectQty: 0,
    defectRate: 0.0,
    inspection: true,
    packaging: true,
    worker: '이성산',
  },
  {
    id: 'wr-7',
    lotNo: 'KD-TS-250201-01-01',
    workDate: '2025-02-01',
    workOrderNo: 'KD-PL-250111-01',
    processType: 'slat',
    productName: '알루미늄 슬랫 셔터',
    specification: '4500x2800',
    productionQty: 2,
    goodQty: 1,
    defectQty: 1,
    defectRate: 50.0,
    inspection: true,
    packaging: true,
    worker: '박철호',
  },
  {
    id: 'wr-8',
    lotNo: 'KD-TS-250130-01-01',
    workDate: '2025-01-30',
    workOrderNo: 'KD-PL-250109-01',
    processType: 'screen',
    productName: '스크린 셔터 (표준형)',
    specification: '7000x2600',
    productionQty: 1,
    goodQty: 1,
    defectQty: 0,
    defectRate: 0.0,
    inspection: true,
    packaging: true,
    worker: '김성산',
  },
];

// 통계 계산
export function calculateWorkResultStats(results: WorkResult[]): WorkResultStats {
  const totalProduction = results.reduce((sum, r) => sum + r.productionQty, 0);
  const totalGood = results.reduce((sum, r) => sum + r.goodQty, 0);
  const totalDefect = results.reduce((sum, r) => sum + r.defectQty, 0);
  const defectRate = totalProduction > 0 ? (totalDefect / totalProduction) * 100 : 0;

  return {
    totalProduction,
    totalGood,
    totalDefect,
    defectRate: Math.round(defectRate * 10) / 10,
  };
}

// 기본 통계
export const mockStats: WorkResultStats = calculateWorkResultStats(mockWorkResults);