/**
 * BOM 기반 견적 산출을 위한 샘플 데이터 생성 유틸리티
 */

export interface BomLine {
  childItemCode: string;
  quantity: number;
  unit: string;
  formula?: string;
  note?: string;
}

export interface SampleBomProduct {
  id: string;
  itemCode: string;
  itemName: string;
  itemType: 'FG' | 'SM' | 'PT';
  itemCategory: string;
  specification: string;
  unit: string;
  manufacturingType?: string;
  description: string;
  bom?: BomLine[];
}

/**
 * BOM 샘플 제품 데이터 생성
 * - 제품의 BOM 구조와 수식을 포함한 샘플 데이터
 */
export function generateBomSampleProducts(): SampleBomProduct[] {
  const timestamp = Date.now();
  
  return [
    // 1. 원자재 및 구매 부품 (BOM 없음)
    {
      id: `material-${timestamp}-1`,
      itemCode: 'MAT-AL-001',
      itemName: '알루미늄 AL6063 판재',
      itemType: 'PT' as const,
      itemCategory: '원자재',
      specification: '3T × 1000 × 2000',
      unit: 'M',
      description: '알루미늄 판재 (AL6063)',
    },
    {
      id: `material-${timestamp}-2`,
      itemCode: 'MAT-STEEL-001',
      itemName: '철재 SPCC 판재',
      itemType: 'PT' as const,
      itemCategory: '원자재',
      specification: '2.5T × 1000 × 2000',
      unit: 'M',
      description: '철재 판재 (SPCC)',
    },
    {
      id: `parts-${timestamp}-1`,
      itemCode: 'PART-MOTOR-220',
      itemName: '셔터 모터 220V',
      itemType: 'PT' as const,
      itemCategory: '모터',
      specification: '220V 0.75KW',
      unit: 'EA',
      description: '셔터용 전동 모터 220V',
    },
    {
      id: `parts-${timestamp}-2`,
      itemCode: 'PART-MOTOR-380',
      itemName: '셔터 모터 380V',
      itemType: 'PT' as const,
      itemCategory: '모터',
      specification: '380V 1.5KW',
      unit: 'EA',
      description: '셔터용 전동 모터 380V',
    },
    {
      id: `parts-${timestamp}-3`,
      itemCode: 'PART-CTRL-SINGLE',
      itemName: '단독 제어기',
      itemType: 'PT' as const,
      itemCategory: '제어기',
      specification: '단독형',
      unit: 'EA',
      description: '단독 제어 시스템',
    },
    {
      id: `parts-${timestamp}-4`,
      itemCode: 'PART-CTRL-GROUP',
      itemName: '그룹 제어기',
      itemType: 'PT' as const,
      itemCategory: '제어기',
      specification: '그룹형',
      unit: 'EA',
      description: '그룹 제어 시스템',
    },
    
    // 2. 가공 부품 (절곡, 용접 등)
    {
      id: `bend-${timestamp}-1`,
      itemCode: 'BEND-TOP-RAIL',
      itemName: '상부레일',
      itemType: 'SM' as const,
      itemCategory: '절곡부품',
      specification: '60×40×3T AL6063',
      unit: 'M',
      manufacturingType: '절곡',
      description: '셔터 상부 가이드레일',
      bom: [
        {
          childItemCode: 'MAT-AL-001',
          quantity: 1,
          unit: 'M',
          formula: '(W0 + 140) / 1000',
          note: '제작폭 기준 알루미늄 소재',
        },
      ],
    },
    {
      id: `bend-${timestamp}-2`,
      itemCode: 'BEND-BOTTOM-RAIL',
      itemName: '하부레일',
      itemType: 'SM' as const,
      itemCategory: '절곡부품',
      specification: '50×30×2.5T AL6063',
      unit: 'M',
      manufacturingType: '절곡',
      description: '셔터 하부 가이드레일',
      bom: [
        {
          childItemCode: 'MAT-AL-001',
          quantity: 1,
          unit: 'M',
          formula: '(W0 + 140) / 1000',
          note: '제작폭 기준 알루미늄 소재',
        },
      ],
    },
    {
      id: `bend-${timestamp}-3`,
      itemCode: 'BEND-SIDE-BRACKET',
      itemName: '측면 브라켓',
      itemType: 'SM' as const,
      itemCategory: '절곡부품',
      specification: '100×80×3T SPCC',
      unit: 'EA',
      manufacturingType: '절곡',
      description: '측면 고정용 브라켓',
      bom: [
        {
          childItemCode: 'MAT-STEEL-001',
          quantity: 0.1,
          unit: 'M',
          note: '철재 판재 0.1M',
        },
      ],
    },
    {
      id: `slat-${timestamp}-1`,
      itemCode: 'SLAT-SCREEN',
      itemName: '스크린 슬랫',
      itemType: 'SM' as const,
      itemCategory: '슬랫',
      specification: '60×40 스크린',
      unit: 'M²',
      manufacturingType: '절곡',
      description: '스크린 슬랫 (면적 기준)',
      bom: [
        {
          childItemCode: 'MAT-AL-001',
          quantity: 1,
          unit: 'M²',
          formula: 'M * 1.1',
          note: '면적 × 1.1 (로스율)',
        },
      ],
    },
    {
      id: `slat-${timestamp}-2`,
      itemCode: 'SLAT-STEEL',
      itemName: '철재 슬랫',
      itemType: 'SM' as const,
      itemCategory: '슬랫',
      specification: '70×50 철재',
      unit: 'M²',
      manufacturingType: '절곡',
      description: '철재 슬랫 (면적 기준)',
      bom: [
        {
          childItemCode: 'MAT-STEEL-001',
          quantity: 1,
          unit: 'M²',
          formula: 'M * 1.15',
          note: '면적 × 1.15 (로스율)',
        },
      ],
    },
    
    // 3. 조립 부품
    {
      id: `assy-${timestamp}-1`,
      itemCode: 'ASSY-SHAFT-4INCH',
      itemName: '감기샤프트 어셈블리 4인치',
      itemType: 'SM' as const,
      itemCategory: '조립부품',
      specification: '4인치 파이프 + 베어링 + 브라켓',
      unit: 'SET',
      manufacturingType: '조립',
      description: '4인치 감기샤프트 완성품',
      bom: [
        {
          childItemCode: 'BEND-TOP-RAIL',
          quantity: 1,
          unit: 'M',
          formula: '(W0 + 140) / 1000',
          note: '제작폭 길이',
        },
        {
          childItemCode: 'BEND-SIDE-BRACKET',
          quantity: 2,
          unit: 'EA',
          note: '좌우 브라켓 2개',
        },
      ],
    },
    
    // 4. 완제품 (셔터)
    {
      id: `product-${timestamp}-1`,
      itemCode: 'SHUTTER-SCREEN-STD',
      itemName: '스크린 셔터 (표준형)',
      itemType: 'FG' as const,
      itemCategory: '셔터',
      specification: '스크린, 감기식',
      unit: 'SET',
      manufacturingType: '제품',
      description: '스크린 감기식 셔터 완제품',
      bom: [
        {
          childItemCode: 'BEND-TOP-RAIL',
          quantity: 1,
          unit: 'M',
          formula: '(W0 + 140) / 1000',
          note: '상부레일 (제작폭)',
        },
        {
          childItemCode: 'BEND-BOTTOM-RAIL',
          quantity: 1,
          unit: 'M',
          formula: '(W0 + 140) / 1000',
          note: '하부레일 (제작폭)',
        },
        {
          childItemCode: 'SLAT-SCREEN',
          quantity: 1,
          unit: 'M²',
          formula: 'M',
          note: '스크린 슬랫 (면적)',
        },
        {
          childItemCode: 'ASSY-SHAFT-4INCH',
          quantity: 1,
          unit: 'SET',
          note: '감기샤프트 어셈블리',
        },
        {
          childItemCode: 'PART-MOTOR-220',
          quantity: 1,
          unit: 'EA',
          note: '모터 (220V 기준)',
        },
        {
          childItemCode: 'PART-CTRL-SINGLE',
          quantity: 1,
          unit: 'EA',
          note: '제어기 (단독 기준)',
        },
      ],
    },
    {
      id: `product-${timestamp}-2`,
      itemCode: 'SHUTTER-STEEL-STD',
      itemName: '철재 셔터 (표준형)',
      itemType: 'FG' as const,
      itemCategory: '셔터',
      specification: '철재, 감기식',
      unit: 'SET',
      manufacturingType: '제품',
      description: '철재 감기식 셔터 완제품',
      bom: [
        {
          childItemCode: 'BEND-TOP-RAIL',
          quantity: 1,
          unit: 'M',
          formula: '(W0 + 110) / 1000',
          note: '상부레일 (제작폭)',
        },
        {
          childItemCode: 'BEND-BOTTOM-RAIL',
          quantity: 1,
          unit: 'M',
          formula: '(W0 + 110) / 1000',
          note: '하부레일 (제작폭)',
        },
        {
          childItemCode: 'SLAT-STEEL',
          quantity: 1,
          unit: 'M²',
          formula: 'M',
          note: '철재 슬랫 (면적)',
        },
        {
          childItemCode: 'ASSY-SHAFT-4INCH',
          quantity: 1,
          unit: 'SET',
          note: '감기샤프트 어셈블리',
        },
        {
          childItemCode: 'PART-MOTOR-380',
          quantity: 1,
          unit: 'EA',
          note: '모터 (380V 기준)',
        },
        {
          childItemCode: 'PART-CTRL-GROUP',
          quantity: 1,
          unit: 'EA',
          note: '제어기 (그룹 기준)',
        },
      ],
    },
  ];
}
