import type { WorkOrder, WorkerStatus, ProcessType } from './types';

// Mock 작업 지시 데이터
export const generateMockWorkOrders = (): WorkOrder[] => {
  const processes: ProcessType[] = ['screen', 'slat', 'bending'];
  const clients = ['삼성물산(주)', '현대건설(주)', '대림건설(주)', '두산건설(주)', '(주)서울인테리어'];
  const projects = [
    '강남 타워 신축현장 (B동)',
    '강남 오피스 A동',
    '해운대 타워',
    '[E2E테스트] 강남 오피스 A동',
    '대치 레이크파크',
    '위례 청라 센트럴파크',
    '판교 물류센터',
    '삼성타운 종합',
    '분당 더 피스트',
    '연수 오피스텔',
  ];
  const productNames = [
    '스크린 서터 (표준형) - 추가',
    '방연셔터 절곡 부품',
    '철재 슬랫 서터',
    '스크린 서터 (대형)',
  ];
  const assigneePool = [
    '김스크린', '박스크린', '이스크린', '최스크린',
    '김슬랫', '박슬랫', '이절곡', '박절곡',
    '이정곡', '김술랫', '박술랫', '이슬랫',
  ];

  const orders: WorkOrder[] = [];

  // 긴급 작업 (5개) - WorkOrders mockData와 매칭
  const urgentOrders = [
    { orderNo: 'KD-WO-251217-12', process: 'screen' as ProcessType, client: '두산건설(주)', project: '위브 청라 센트럴파크', dueDate: '2025-12-30', status: 'completed' as const },
    { orderNo: 'KD-WO-251217-11', process: 'screen' as ProcessType, client: '대영건설(주)', project: '대시앙 동탄 레이크파크', dueDate: '2026-02-08', status: 'inProgress' as const },
    { orderNo: 'KD-WO-FLD-251216-01', process: 'bending' as ProcessType, client: '삼성물산(주)', project: '[E2E테스트] 절곡 전용 현장', dueDate: '2025-12-28', status: 'inProgress' as const },
    { orderNo: 'KD-WO-251217-10', process: 'screen' as ProcessType, client: '포레나', project: '포레나 수지 더 퍼스트', dueDate: '2026-02-13', status: 'waiting' as const },
    { orderNo: 'KD-WO-251217-09', process: 'slat' as ProcessType, client: '호반건설(주)', project: '써밋 광교 리버파크', dueDate: '2026-01-30', status: 'inProgress' as const },
  ];

  urgentOrders.forEach((item, i) => {
    orders.push({
      id: `urgent-${i + 1}`,
      orderNo: item.orderNo,
      productName: productNames[i % productNames.length],
      process: item.process,
      client: item.client,
      projectName: item.project,
      assignees: [assigneePool[i % assigneePool.length]],
      quantity: (i % 5) + 2, // 고정값 (2~6)
      dueDate: item.dueDate,
      priority: i + 1,
      status: item.status,
      isUrgent: true,
      isDelayed: false,
      instruction: i === 0 ? '추가분 주문, 기존 납품분과 동일 사양 유지' : undefined,
      createdAt: '2025-12-20T09:00:00.000Z', // 고정값
    });
  });

  // 지연 작업 (5개) - WorkOrders mockData와 매칭
  const delayedOrders = [
    { orderNo: 'KD-WO-251217-08', process: 'screen' as ProcessType, client: '삼성물산(주)', delayDays: 5 },
    { orderNo: 'KD-WO-251217-07', process: 'screen' as ProcessType, client: '삼성물산(주)', delayDays: 3 },
    { orderNo: 'KD-WO-FLD-251215-01', process: 'bending' as ProcessType, client: '삼성물산(주)', delayDays: 7 },
    { orderNo: 'KD-WO-FLD-251212-01', process: 'bending' as ProcessType, client: '삼성물산(주)', delayDays: 10 },
    { orderNo: 'KD-WO-FLD-251208-01', process: 'screen' as ProcessType, client: '삼성물산(주)', delayDays: 1 },
  ];

  delayedOrders.forEach((item, i) => {
    orders.push({
      id: `delayed-${i + 1}`,
      orderNo: item.orderNo,
      productName: productNames[i % productNames.length],
      process: item.process,
      client: item.client,
      projectName: projects[i % projects.length],
      assignees: [assigneePool[(i + 5) % assigneePool.length], assigneePool[(i + 6) % assigneePool.length]],
      quantity: (i % 5) + 2, // 고정값 (2~6)
      dueDate: '2025-01-15',
      priority: i + 1,
      status: 'inProgress',
      isUrgent: false,
      isDelayed: true,
      delayDays: item.delayDays,
      createdAt: '2025-12-20T09:00:00.000Z', // 고정값
    });
  });

  // 일반 작업 (추가) - 대기/작업중 상태 위주로 추가
  for (let i = 0; i < 22; i++) {
    const process = processes[i % 3];
    // completed 비율을 줄이고 waiting/inProgress 위주로 생성
    const statusOptions: Array<'waiting' | 'inProgress' | 'completed'> = ['waiting', 'waiting', 'inProgress', 'inProgress', 'inProgress', 'completed'];
    orders.push({
      id: `work-${i + 1}`,
      orderNo: `KD-WO-${process === 'bending' ? 'FLD-' : ''}25${String(12).padStart(2, '0')}${String(i + 1).padStart(2, '0')}-${String((i % 3) + 1).padStart(2, '0')}`,
      productName: productNames[i % productNames.length],
      process,
      client: clients[i % clients.length],
      projectName: projects[i % projects.length],
      assignees: [assigneePool[i % assigneePool.length]],
      quantity: (i % 8) + 3, // 고정값 (3~10)
      dueDate: `2025-${String((i % 3) + 1).padStart(2, '0')}-${String((i % 28) + 1).padStart(2, '0')}`,
      priority: (i % 5) + 1,
      status: statusOptions[i % statusOptions.length],
      isUrgent: false,
      isDelayed: false,
      createdAt: '2025-12-20T09:00:00.000Z', // 고정값
    });
  }

  // 작업자 화면용 추가 데이터 (대기/작업중 상태만)
  const additionalWaitingOrders = [
    { orderNo: 'KD-WO-251201-01', process: 'screen' as ProcessType, client: '삼성물산(주)', project: '강남 타워 신축현장 (B동)', product: '스크린 서터 (표준형) - 추가', quantity: 3, priority: 1 },
    { orderNo: 'KD-WO-251202-02', process: 'slat' as ProcessType, client: '현대건설(주)', project: '해운대 타워', product: '철재 슬랫 서터', quantity: 5, priority: 2 },
    { orderNo: 'KD-WO-251203-03', process: 'screen' as ProcessType, client: '대림건설(주)', project: '대치 레이크파크', product: '스크린 서터 (대형)', quantity: 2, priority: 3 },
    { orderNo: 'KD-WO-FLD-251204-01', process: 'bending' as ProcessType, client: '두산건설(주)', project: '위례 청라 센트럴파크', product: '방연셔터 절곡 부품', quantity: 8, priority: 1 },
    { orderNo: 'KD-WO-251205-04', process: 'screen' as ProcessType, client: '(주)서울인테리어', project: '판교 물류센터', product: '스크린 서터 (표준형) - 추가', quantity: 4, priority: 2 },
  ];

  additionalWaitingOrders.forEach((item, i) => {
    orders.push({
      id: `additional-waiting-${i + 1}`,
      orderNo: item.orderNo,
      productName: item.product,
      process: item.process,
      client: item.client,
      projectName: item.project,
      assignees: [assigneePool[i % assigneePool.length]],
      quantity: item.quantity,
      dueDate: '2025-01-01',
      priority: item.priority,
      status: 'waiting',
      isUrgent: i === 0 || i === 3, // 1, 4번째 긴급
      isDelayed: false,
      instruction: i === 0 ? '추가분 주문, 기존 납품분과 동일 사양 유지' : undefined,
      createdAt: '2025-12-20T09:00:00.000Z',
    });
  });

  return orders;
};

// Mock 작업자 현황 데이터
export const generateMockWorkerStatus = (): WorkerStatus[] => {
  return [
    { id: 'w1', name: '김스크린', inProgress: 4, completed: 4, assigned: 9 },
    { id: 'w2', name: '박스크린', inProgress: 4, completed: 4, assigned: 5 },
    { id: 'w3', name: '김슬랫', inProgress: 0, completed: 3, assigned: 5 },
    { id: 'w4', name: '박슬랫', inProgress: 0, completed: 2, assigned: 2 },
    { id: 'w5', name: '이스크린', inProgress: 1, completed: 1, assigned: 2 },
    { id: 'w6', name: '최절곡', inProgress: 0, completed: 2, assigned: 3 },
    { id: 'w7', name: '이절곡', inProgress: 1, completed: 0, assigned: 1 },
    { id: 'w8', name: '최스크린', inProgress: 0, completed: 1, assigned: 2 },
  ];
};
