// 견적 산출 샘플 데이터 생성 유틸리티
import type { ItemMaster, PricingData } from '../components/contexts/DataContext';

export function createSampleQuoteData() {
  const timestamp = Date.now();
  const newItems: ItemMaster[] = [];
  
  // ===== 1. 원자재 (RM) 20종 - 가장 하위 계층 =====
  const rawMaterials = [
    { code: 'RM-S001', name: '강판 1.2T', unit: 'KG', price: 3500 },
    { code: 'RM-S002', name: '강판 1.6T', unit: 'KG', price: 3800 },
    { code: 'RM-S003', name: '강판 2.0T', unit: 'KG', price: 4200 },
    { code: 'RM-S004', name: '강판 2.3T', unit: 'KG', price: 4500 },
    { code: 'RM-A001', name: '알루미늄 프로파일', unit: 'M', price: 15000 },
    { code: 'RM-A002', name: '알루미늄 판재 2.0T', unit: 'KG', price: 8500 },
    { code: 'RM-P001', name: '파우더 도료 (흰색)', unit: 'KG', price: 12000 },
    { code: 'RM-P002', name: '파우더 도료 (검정)', unit: 'KG', price: 12000 },
    { code: 'RM-P003', name: '파우더 도료 (회색)', unit: 'KG', price: 12000 },
    { code: 'RM-F001', name: '방화원단 A급', unit: 'M2', price: 28000 },
    { code: 'RM-F002', name: '방화원단 B급', unit: 'M2', price: 22000 },
    { code: 'RM-R001', name: '고무 패킹 3mm', unit: 'M', price: 3500 },
    { code: 'RM-R002', name: '고무 패킹 5mm', unit: 'M', price: 4200 },
    { code: 'RM-W001', name: '목재 (집성목)', unit: 'M', price: 25000 },
    { code: 'RM-G001', name: '유리섬유', unit: 'KG', price: 15000 },
    { code: 'RM-I001', name: '단열재 50mm', unit: 'M2', price: 12000 },
    { code: 'RM-I002', name: '단열재 100mm', unit: 'M2', price: 18000 },
    { code: 'RM-C001', name: '케이블 피복재', unit: 'M', price: 2800 },
    { code: 'RM-ST001', name: 'STS304 판재', unit: 'KG', price: 9500 },
    { code: 'RM-Z001', name: '아연도금강판', unit: 'KG', price: 4800 },
  ];
  
  rawMaterials.forEach((mat, idx) => {
    newItems.push({
      id: `RM-${timestamp}-${idx}`,
      itemCode: mat.code,
      itemName: mat.name,
      itemType: 'RM',
      unit: mat.unit,
      salesPrice: mat.price,
      purchasePrice: Math.round(mat.price * 0.75),
      specification: '원자재',
      bom: [], // 원자재는 BOM 없음
      createdAt: new Date().toISOString(),
      updatedAt: new Date().toISOString(),
      status: '활성'
    });
  });
  
  // ===== 2. 부자재 (SM) 25종 =====
  const subMaterials = [
    { code: 'SM-B001', name: '볼트 M8x30', unit: 'EA', price: 150 },
    { code: 'SM-B002', name: '볼트 M10x40', unit: 'EA', price: 200 },
    { code: 'SM-B003', name: '볼트 M12x50', unit: 'EA', price: 280 },
    { code: 'SM-N001', name: '너트 M8', unit: 'EA', price: 80 },
    { code: 'SM-N002', name: '너트 M10', unit: 'EA', price: 100 },
    { code: 'SM-N003', name: '너트 M12', unit: 'EA', price: 120 },
    { code: 'SM-W001', name: '와셔 M8', unit: 'EA', price: 50 },
    { code: 'SM-W002', name: '와셔 M10', unit: 'EA', price: 60 },
    { code: 'SM-W003', name: '와셔 M12', unit: 'EA', price: 70 },
    { code: 'SM-R001', name: '리벳 4x10', unit: 'EA', price: 40 },
    { code: 'SM-R002', name: '리벳 5x12', unit: 'EA', price: 50 },
    { code: 'SM-A001', name: '앵커볼트 M10', unit: 'EA', price: 350 },
    { code: 'SM-A002', name: '앵커볼트 M12', unit: 'EA', price: 450 },
    { code: 'SM-S001', name: '실리콘 (투명)', unit: 'EA', price: 8500 },
    { code: 'SM-S002', name: '실리콘 (백색)', unit: 'EA', price: 8500 },
    { code: 'SM-T001', name: '양면테이프 20mm', unit: 'M', price: 1200 },
    { code: 'SM-C001', name: '케이블타이 200mm', unit: 'EA', price: 100 },
    { code: 'SM-P001', name: '보호필름', unit: 'M2', price: 2500 },
    { code: 'SM-G001', name: '그리스', unit: 'EA', price: 12000 },
    { code: 'SM-O001', name: '윤활유', unit: 'L', price: 15000 },
    { code: 'SM-E001', name: '전선 2.5SQ', unit: 'M', price: 1800 },
    { code: 'SM-E002', name: '전선 4.0SQ', unit: 'M', price: 2500 },
    { code: 'SM-L001', name: 'LED 표시등', unit: 'EA', price: 5500 },
    { code: 'SM-WD001', name: '용접봉 3.2mm', unit: 'KG', price: 8500 },
    { code: 'SM-SP001', name: '스프링와셔 M10', unit: 'EA', price: 90 },
  ];
  
  subMaterials.forEach((mat, idx) => {
    newItems.push({
      id: `SM-${timestamp}-${idx}`,
      itemCode: mat.code,
      itemName: mat.name,
      itemType: 'SM',
      unit: mat.unit,
      salesPrice: mat.price,
      purchasePrice: Math.round(mat.price * 0.8),
      specification: '공용 부자재',
      bom: [],
      createdAt: new Date().toISOString(),
      updatedAt: new Date().toISOString(),
      status: '활성'
    });
  });
  
  // ===== 3. 반제품 (SF) - 스크린용 부품 20종 (원자재로 구성) =====
  const screenParts = [
    { code: 'SF-SCR-F01', name: '스크린 원단', unit: 'M2', price: 35000, hasBom: true },
    { code: 'SF-SCR-F02', name: '가이드레일 (좌)', unit: 'M', price: 42000, hasBom: true },
    { code: 'SF-SCR-F03', name: '가이드레일 (우)', unit: 'M', price: 42000, hasBom: true },
    { code: 'SF-SCR-F04', name: '상부 케이스', unit: 'EA', price: 145000, hasBom: true },
    { code: 'SF-SCR-F05', name: '하부 바텀바', unit: 'EA', price: 55000, hasBom: true },
    { code: 'SF-SCR-M01', name: '모터 (0.75KW)', unit: 'EA', price: 350000, hasBom: false },
    { code: 'SF-SCR-M02', name: '모터 (1.5KW)', unit: 'EA', price: 480000, hasBom: false },
    { code: 'SF-SCR-M03', name: '모터 (2.2KW)', unit: 'EA', price: 620000, hasBom: false },
    { code: 'SF-SCR-M04', name: '모터 (3.7KW)', unit: 'EA', price: 850000, hasBom: false },
    { code: 'SF-SCR-C01', name: '제어반 (표준)', unit: 'EA', price: 280000, hasBom: false },
    { code: 'SF-SCR-C02', name: '제어반 (고급)', unit: 'EA', price: 450000, hasBom: false },
    { code: 'SF-SCR-S01', name: '감지기 세트', unit: 'SET', price: 180000, hasBom: false },
    { code: 'SF-SCR-W01', name: '권취축', unit: 'EA', price: 125000, hasBom: true },
    { code: 'SF-SCR-B01', name: '브라켓 세트', unit: 'SET', price: 78000, hasBom: true },
    { code: 'SF-SCR-E01', name: '엣지윙 (좌)', unit: 'M', price: 15000, hasBom: true },
    { code: 'SF-SCR-E02', name: '엣지윙 (우)', unit: 'M', price: 15000, hasBom: true },
    { code: 'SF-SCR-SP01', name: '스프링 세트', unit: 'SET', price: 45000, hasBom: false },
    { code: 'SF-SCR-CH01', name: '체인 세트', unit: 'SET', price: 65000, hasBom: false },
    { code: 'SF-SCR-REM01', name: '리모컨', unit: 'EA', price: 85000, hasBom: false },
    { code: 'SF-SCR-SW01', name: '스위치 BOX', unit: 'EA', price: 45000, hasBom: true },
  ];
  
  screenParts.forEach((part, idx) => {
    const item: ItemMaster = {
      id: `SF-SCR-${timestamp}-${idx}`,
      itemCode: part.code,
      itemName: part.name,
      itemType: 'SF',
      productCategory: 'SCREEN',
      unit: part.unit,
      salesPrice: part.price,
      purchasePrice: Math.round(part.price * 0.65),
      specification: '스크린용 반제품',
      bom: [],
      createdAt: new Date().toISOString(),
      updatedAt: new Date().toISOString(),
      status: '활성'
    };
    
    // BOM 구조 추가
    if (part.hasBom) {
      switch (part.code) {
        case 'SF-SCR-F01': // 스크린 원단
          item.bom = [
            { childItemCode: 'RM-F001', childItemName: '방화원단 A급', quantity: 1.1, unit: 'M2', quantityFormula: '', note: 'LOSS 10%' },
            { childItemCode: 'SM-T001', childItemName: '양면테이프 20mm', quantity: 2, unit: 'M', quantityFormula: '', note: '가공용' },
          ];
          break;
        case 'SF-SCR-F02': // 가이드레일 좌
        case 'SF-SCR-F03': // 가이드레일 우
          item.bom = [
            { childItemCode: 'RM-A001', childItemName: '알루미늄 프로파일', quantity: 1.05, unit: 'M', quantityFormula: '', note: 'LOSS 5%' },
            { childItemCode: 'RM-P001', childItemName: '파우더 도료 (흰색)', quantity: 0.15, unit: 'KG', quantityFormula: '', note: '표면처리' },
            { childItemCode: 'RM-R001', childItemName: '고무 패킹 3mm', quantity: 1, unit: 'M', quantityFormula: '', note: '' },
          ];
          break;
        case 'SF-SCR-F04': // 상부 케이스
          item.bom = [
            { childItemCode: 'RM-S002', childItemName: '강판 1.6T', quantity: 12, unit: 'KG', quantityFormula: '', note: '' },
            { childItemCode: 'RM-P002', childItemName: '파우더 도료 (검정)', quantity: 0.8, unit: 'KG', quantityFormula: '', note: '표면처리' },
            { childItemCode: 'SM-B002', childItemName: '볼트 M10x40', quantity: 8, unit: 'EA', quantityFormula: '', note: '조립용' },
            { childItemCode: 'SM-N002', childItemName: '너트 M10', quantity: 8, unit: 'EA', quantityFormula: '', note: '' },
          ];
          break;
        case 'SF-SCR-F05': // 하부 바텀바
          item.bom = [
            { childItemCode: 'RM-A002', childItemName: '알루미늄 판재 2.0T', quantity: 3, unit: 'KG', quantityFormula: '', note: '' },
            { childItemCode: 'RM-R002', childItemName: '고무 패킹 5mm', quantity: 1, unit: 'M', quantityFormula: '', note: '하부 실링' },
            { childItemCode: 'SM-WD001', childItemName: '용접봉 3.2mm', quantity: 0.2, unit: 'KG', quantityFormula: '', note: '용접' },
          ];
          break;
        case 'SF-SCR-W01': // 권취축
          item.bom = [
            { childItemCode: 'RM-S003', childItemName: '강판 2.0T', quantity: 15, unit: 'KG', quantityFormula: '', note: '롤 제작' },
            { childItemCode: 'SM-G001', childItemName: '그리스', quantity: 0.3, unit: 'EA', quantityFormula: '', note: '윤활' },
          ];
          break;
        case 'SF-SCR-B01': // 브라켓 세트
          item.bom = [
            { childItemCode: 'RM-S002', childItemName: '강판 1.6T', quantity: 5, unit: 'KG', quantityFormula: '', note: '' },
            { childItemCode: 'SM-B002', childItemName: '볼트 M10x40', quantity: 6, unit: 'EA', quantityFormula: '', note: '' },
            { childItemCode: 'SM-N002', childItemName: '너트 M10', quantity: 6, unit: 'EA', quantityFormula: '', note: '' },
          ];
          break;
        case 'SF-SCR-E01': // 엣지윙 좌
        case 'SF-SCR-E02': // 엣지윙 우
          item.bom = [
            { childItemCode: 'RM-A001', childItemName: '알루미늄 프로파일', quantity: 1.03, unit: 'M', quantityFormula: '', note: 'LOSS 3%' },
          ];
          break;
        case 'SF-SCR-SW01': // 스위치 BOX
          item.bom = [
            { childItemCode: 'RM-S001', childItemName: '강판 1.2T', quantity: 2, unit: 'KG', quantityFormula: '', note: '' },
            { childItemCode: 'SM-E001', childItemName: '전선 2.5SQ', quantity: 3, unit: 'M', quantityFormula: '', note: '' },
            { childItemCode: 'SM-L001', childItemName: 'LED 표시등', quantity: 2, unit: 'EA', quantityFormula: '', note: '' },
          ];
          break;
      }
    }
    
    newItems.push(item);
  });
  
  // ===== 4. 반제품 (SF) - 철재용 부품 20종 (원자재로 구성, 절곡 포함) =====
  const steelParts = [
    { code: 'SF-STL-D01', name: '철재 도어', unit: 'EA', price: 320000, hasBom: true },
    { code: 'SF-STL-F01', name: '철재 프레임', unit: 'M', price: 58000, hasBom: true },
    { code: 'SF-STL-P01', name: '철재 패널', unit: 'M2', price: 68000, hasBom: true },
    { code: 'SF-STL-H01', name: '경첩 세트 (표준)', unit: 'SET', price: 42000, hasBom: false },
    { code: 'SF-STL-H02', name: '경첩 세트 (중형)', unit: 'SET', price: 58000, hasBom: false },
    { code: 'SF-STL-L01', name: '도어락 (기계식)', unit: 'EA', price: 95000, hasBom: false },
    { code: 'SF-STL-L02', name: '도어락 (전자식)', unit: 'EA', price: 380000, hasBom: false },
    { code: 'SF-STL-C01', name: '도어클로저', unit: 'EA', price: 115000, hasBom: false },
    { code: 'SF-STL-S01', name: '실링재', unit: 'M', price: 9500, hasBom: false },
    { code: 'SF-STL-G01', name: '유리 (방화)', unit: 'M2', price: 220000, hasBom: false },
    { code: 'SF-STL-T01', name: '문턱', unit: 'EA', price: 58000, hasBom: true },
    { code: 'SF-STL-V01', name: '환기구', unit: 'EA', price: 75000, hasBom: false },
    { code: 'SF-STL-K01', name: '킥플레이트', unit: 'EA', price: 45000, hasBom: true },
    { code: 'SF-STL-W01', name: '창틀', unit: 'M', price: 35000, hasBom: true },
    { code: 'SF-STL-B01', name: '볼트/너트 세트', unit: 'SET', price: 18000, hasBom: false },
    { code: 'SF-STL-P02', name: '파우더 도장', unit: 'M2', price: 32000, hasBom: true },
    { code: 'SF-BND-L01', name: '절곡 L형 브라켓', unit: 'EA', price: 28000, hasBom: true },
    { code: 'SF-BND-U01', name: '절곡 U형 채널', unit: 'M', price: 42000, hasBom: true },
    { code: 'SF-BND-Z01', name: '절곡 Z형 앵글', unit: 'M', price: 38000, hasBom: true },
    { code: 'SF-BND-C01', name: '절곡 ㄷ형 보강재', unit: 'M', price: 35000, hasBom: true },
  ];
  
  steelParts.forEach((part, idx) => {
    const item: ItemMaster = {
      id: `SF-STL-${timestamp}-${idx}`,
      itemCode: part.code,
      itemName: part.name,
      itemType: 'SF',
      productCategory: 'STEEL',
      unit: part.unit,
      salesPrice: part.price,
      purchasePrice: Math.round(part.price * 0.65),
      specification: part.code.includes('BND') ? '절곡 반제품' : '철재용 반제품',
      bom: [],
      createdAt: new Date().toISOString(),
      updatedAt: new Date().toISOString(),
      status: '활성'
    };
    
    // BOM 구조 추가
    if (part.hasBom) {
      switch (part.code) {
        case 'SF-STL-D01': // 철재 도어
          item.bom = [
            { childItemCode: 'RM-S003', childItemName: '강판 2.0T', quantity: 45, unit: 'KG', quantityFormula: '', note: '도어 본체' },
            { childItemCode: 'RM-I002', childItemName: '단열재 100mm', quantity: 2, unit: 'M2', quantityFormula: '', note: '충진재' },
            { childItemCode: 'RM-P001', childItemName: '파우더 도료 (흰색)', quantity: 1.5, unit: 'KG', quantityFormula: '', note: '표면처리' },
            { childItemCode: 'SM-WD001', childItemName: '용접봉 3.2mm', quantity: 1, unit: 'KG', quantityFormula: '', note: '용접' },
          ];
          break;
        case 'SF-STL-F01': // 철재 프레임
          item.bom = [
            { childItemCode: 'RM-S002', childItemName: '강판 1.6T', quantity: 8, unit: 'KG', quantityFormula: '', note: '프레임' },
            { childItemCode: 'SM-WD001', childItemName: '용접봉 3.2mm', quantity: 0.3, unit: 'KG', quantityFormula: '', note: '용접' },
            { childItemCode: 'RM-P002', childItemName: '파우더 도료 (검정)', quantity: 0.5, unit: 'KG', quantityFormula: '', note: '표면처리' },
          ];
          break;
        case 'SF-STL-P01': // 철재 패널
          item.bom = [
            { childItemCode: 'RM-S002', childItemName: '강판 1.6T', quantity: 15, unit: 'KG', quantityFormula: '', note: '패널' },
            { childItemCode: 'RM-I001', childItemName: '단열재 50mm', quantity: 1, unit: 'M2', quantityFormula: '', note: '단열' },
            { childItemCode: 'RM-P003', childItemName: '파우더 도료 (회색)', quantity: 0.8, unit: 'KG', quantityFormula: '', note: '표면처리' },
          ];
          break;
        case 'SF-STL-T01': // 문턱
          item.bom = [
            { childItemCode: 'RM-A002', childItemName: '알루미늄 판재 2.0T', quantity: 3, unit: 'KG', quantityFormula: '', note: '' },
            { childItemCode: 'RM-R001', childItemName: '고무 패킹 3mm', quantity: 0.5, unit: 'M', quantityFormula: '', note: '실링' },
          ];
          break;
        case 'SF-STL-K01': // 킥플레이트
          item.bom = [
            { childItemCode: 'RM-ST001', childItemName: 'STS304 판재', quantity: 2, unit: 'KG', quantityFormula: '', note: '스테인리스' },
            { childItemCode: 'SM-R001', childItemName: '리벳 4x10', quantity: 12, unit: 'EA', quantityFormula: '', note: '고정용' },
          ];
          break;
        case 'SF-STL-W01': // 창틀
          item.bom = [
            { childItemCode: 'RM-A001', childItemName: '알루미늄 프로파일', quantity: 1.05, unit: 'M', quantityFormula: '', note: 'LOSS 5%' },
            { childItemCode: 'RM-R001', childItemName: '고무 패킹 3mm', quantity: 1, unit: 'M', quantityFormula: '', note: '실링' },
          ];
          break;
        case 'SF-STL-P02': // 파우더 도장
          item.bom = [
            { childItemCode: 'RM-P001', childItemName: '파우더 도료 (흰색)', quantity: 0.5, unit: 'KG', quantityFormula: '', note: '도장' },
          ];
          break;
        case 'SF-BND-L01': // 절곡 L형 브라켓
          item.bom = [
            { childItemCode: 'RM-S002', childItemName: '강판 1.6T', quantity: 2.5, unit: 'KG', quantityFormula: '', note: '절곡가공' },
            { childItemCode: 'RM-P002', childItemName: '파우더 도료 (검정)', quantity: 0.2, unit: 'KG', quantityFormula: '', note: '표면처리' },
            { childItemCode: 'SM-B002', childItemName: '볼트 M10x40', quantity: 4, unit: 'EA', quantityFormula: '', note: '고정용' },
          ];
          item.specification = '절곡가공 L형 (90도 절곡)';
          break;
        case 'SF-BND-U01': // 절곡 U형 채널
          item.bom = [
            { childItemCode: 'RM-S003', childItemName: '강판 2.0T', quantity: 4, unit: 'KG', quantityFormula: '', note: '절곡가공' },
            { childItemCode: 'RM-Z001', childItemName: '아연도금강판', quantity: 0.5, unit: 'KG', quantityFormula: '', note: '보강' },
            { childItemCode: 'SM-WD001', childItemName: '용접봉 3.2mm', quantity: 0.1, unit: 'KG', quantityFormula: '', note: '용접' },
          ];
          item.specification = '절곡가공 U형 (2회 절곡)';
          break;
        case 'SF-BND-Z01': // 절곡 Z형 앵글
          item.bom = [
            { childItemCode: 'RM-S002', childItemName: '강판 1.6T', quantity: 3.2, unit: 'KG', quantityFormula: '', note: '절곡가공' },
            { childItemCode: 'RM-P003', childItemName: '파우더 도료 (회색)', quantity: 0.25, unit: 'KG', quantityFormula: '', note: '표면처리' },
          ];
          item.specification = '절곡가공 Z형 (2회 절곡, S자 형태)';
          break;
        case 'SF-BND-C01': // 절곡 ㄷ형 보강재
          item.bom = [
            { childItemCode: 'RM-S004', childItemName: '강판 2.3T', quantity: 3.8, unit: 'KG', quantityFormula: '', note: '절곡가공' },
            { childItemCode: 'RM-P001', childItemName: '파우더 도료 (흰색)', quantity: 0.3, unit: 'KG', quantityFormula: '', note: '표면처리' },
            { childItemCode: 'SM-B003', childItemName: '볼트 M12x50', quantity: 6, unit: 'EA', quantityFormula: '', note: '고정용' },
          ];
          item.specification = '절곡가공 ㄷ형 (2회 절곡, 보강용)';
          break;
      }
    }
    
    newItems.push(item);
  });
  
  return { items: newItems };
}
