import type { FormulaRule } from "./contexts/DataContext";

/**
 * 가이드레일 산정 기준 생성 함수 (첨부 이미지 기준)
 * 스크린/철재 × 벽면형/측면형 = 4개 가이드레일 규칙
 * 하부 Base = 4개 규칙
 * 총 8개 규칙 생성
 */
export function generateGuideRailRules(): FormulaRule[] {
  const timestamp = Date.now();
  
  return [
    // 1. 스크린 벽면형 가이드레일 (120×70 규격)
    {
      id: `rule-gr-screen-wall-${timestamp}`,
      ruleCode: 'GUIDE-RAIL-SCREEN-WALL',
      ruleName: '가이드레일 품목 선택 (스크린-벽면형)',
      category: 'guide-rail',
      subcategory: '스크린-벽면형',
      ruleType: 'range',
      description: '스크린 벽면형 설치: 가이드레일 120×70 규격, 제작길이(G=H0+250) 구간별 품목 선택 (2방 1SET 기준)',
      inputVariable: 'G',
      status: 'active',
      ranges: [
        { id: `range-${timestamp}-scw1`, minValue: 1219, maxValue: 2438, result: '가이드레일-120*70*2438 x2개', itemCode: 'GR-SCR-WALL-2438', itemName: '가이드레일-120*70*2438', quantity: 2, description: '1219 < G ≤ 2438: 120×70×2438 x2개' },
        { id: `range-${timestamp}-scw2`, minValue: 2439, maxValue: 3000, result: '가이드레일-120*70*3000 x2개', itemCode: 'GR-SCR-WALL-3000', itemName: '가이드레일-120*70*3000', quantity: 2, description: '2438 < G ≤ 3000: 120×70×3000 x2개' },
        { id: `range-${timestamp}-scw3`, minValue: 3001, maxValue: 3500, result: '가이드레일-120*70*3500 x2개', itemCode: 'GR-SCR-WALL-3500', itemName: '가이드레일-120*70*3500', quantity: 2, description: '3000 < G ≤ 3500: 120×70×3500 x2개' },
        { id: `range-${timestamp}-scw4`, minValue: 3501, maxValue: 4000, result: '가이드레일-120*70*4000 x2개', itemCode: 'GR-SCR-WALL-4000', itemName: '가이드레일-120*70*4000', quantity: 2, description: '3500 < G ≤ 4000: 120×70×4000 x2개' },
        { id: `range-${timestamp}-scw5`, minValue: 4001, maxValue: 4300, result: '가이드레일-120*70*4300 x2개', itemCode: 'GR-SCR-WALL-4300', itemName: '가이드레일-120*70*4300', quantity: 2, description: '4000 < G ≤ 4300: 120×70×4300 x2개' },
        { id: `range-${timestamp}-scw6`, minValue: 4301, maxValue: 5438, result: '가이드레일-120*70*3000 x2 + 가이드레일-120*70*3500 x2', itemCode: 'GR-SCR-WALL-COMBO-3000-3500', itemName: '가이드레일 조합 (120×70×3000+3500)', quantity: 1, description: '4300 < G ≤ 5438: 3000×2 + 3500×2' },
        { id: `range-${timestamp}-scw7`, minValue: 5439, maxValue: 6438, result: '가이드레일-120*70*3000 x2 + 가이드레일-120*70*4000 x2', itemCode: 'GR-SCR-WALL-COMBO-3000-4000', itemName: '가이드레일 조합 (120×70×3000+4000)', quantity: 1, description: '5438 < G ≤ 6438: 3000×2 + 4000×2' },
        { id: `range-${timestamp}-scw8`, minValue: 6439, maxValue: 6738, result: '가이드레일-120*70*3000 x2 + 가이드레일-120*70*4300 x2', itemCode: 'GR-SCR-WALL-COMBO-3000-4300', itemName: '가이드레일 조합 (120×70×3000+4300)', quantity: 1, description: '6438 < G ≤ 6738: 3000×2 + 4300×2' },
        { id: `range-${timestamp}-scw9`, minValue: 6739, maxValue: 7438, result: '가이드레일-120*70*3500 x4개', itemCode: 'GR-SCR-WALL-3500', itemName: '가이드레일-120*70*3500', quantity: 4, description: '6738 < G ≤ 7438: 3500×4개' },
        { id: `range-${timestamp}-scw10`, minValue: 7439, maxValue: 8600, result: '가이드레일-120*70*4000 x2 + 가이드레일-120*70*4300 x2', itemCode: 'GR-SCR-WALL-COMBO-4000-4300', itemName: '가이드레일 조합 (120×70×4000+4300)', quantity: 1, description: '7438 < G ≤ 8600: 4000×2 + 4300×2' }
      ],
      currentRevision: 0,
      isFinal: false,
      createdAt: new Date().toISOString().split('T')[0],
      createdBy: '시스템',
      updatedAt: new Date().toISOString().split('T')[0]
    },
    
    // 2. 스크린 측면형 가이드레일 (120×120 규격)
    {
      id: `rule-gr-screen-side-${timestamp}`,
      ruleCode: 'GUIDE-RAIL-SCREEN-SIDE',
      ruleName: '가이드레일 품목 선택 (스크린-측면형)',
      category: 'guide-rail',
      subcategory: '스크린-측면형',
      ruleType: 'range',
      description: '스크린 측면형 설치: 가이드레일 120×120 규격, 제작길이(G=H0+250) 구간별 품목 선택 (2방 1SET 기준)',
      inputVariable: 'G',
      status: 'active',
      ranges: [
        { id: `range-${timestamp}-scs1`, minValue: 1219, maxValue: 2438, result: '가이드레일-120*120*2438 x2개', itemCode: 'GR-SCR-SIDE-2438', itemName: '가이드레일-120*120*2438', quantity: 2, description: '1219 < G ≤ 2438: 120×120×2438 x2개' },
        { id: `range-${timestamp}-scs2`, minValue: 2439, maxValue: 3000, result: '가이드레일-120*120*3000 x2개', itemCode: 'GR-SCR-SIDE-3000', itemName: '가이드레일-120*120*3000', quantity: 2, description: '2438 < G ≤ 3000: 120×120×3000 x2개' },
        { id: `range-${timestamp}-scs3`, minValue: 3001, maxValue: 3500, result: '가이드레일-120*120*3500 x2개', itemCode: 'GR-SCR-SIDE-3500', itemName: '가이드레일-120*120*3500', quantity: 2, description: '3000 < G ≤ 3500: 120×120×3500 x2개' },
        { id: `range-${timestamp}-scs4`, minValue: 3501, maxValue: 4000, result: '가이드레일-120*120*4000 x2개', itemCode: 'GR-SCR-SIDE-4000', itemName: '가이드레일-120*120*4000', quantity: 2, description: '3500 < G ≤ 4000: 120×120×4000 x2개' },
        { id: `range-${timestamp}-scs5`, minValue: 4001, maxValue: 4300, result: '가이드레일-120*120*4300 x2개', itemCode: 'GR-SCR-SIDE-4300', itemName: '가이드레일-120*120*4300', quantity: 2, description: '4000 < G ≤ 4300: 120×120×4300 x2개' },
        { id: `range-${timestamp}-scs6`, minValue: 4301, maxValue: 5438, result: '가이드레일-120*120*3000 x2 + 가이드레일-120*120*3500 x2', itemCode: 'GR-SCR-SIDE-COMBO-3000-3500', itemName: '가이드레일 조합 (120×120×3000+3500)', quantity: 1, description: '4300 < G ≤ 5438: 3000×2 + 3500×2' },
        { id: `range-${timestamp}-scs7`, minValue: 5439, maxValue: 6438, result: '가이드레일-120*120*3000 x2 + 가이드레일-120*120*4000 x2', itemCode: 'GR-SCR-SIDE-COMBO-3000-4000', itemName: '가이드레일 조합 (120×120×3000+4000)', quantity: 1, description: '5438 < G ≤ 6438: 3000×2 + 4000×2' },
        { id: `range-${timestamp}-scs8`, minValue: 6439, maxValue: 6738, result: '가이드레일-120*120*3000 x2 + 가이드레일-120*120*4300 x2', itemCode: 'GR-SCR-SIDE-COMBO-3000-4300', itemName: '가이드레일 조합 (120×120×3000+4300)', quantity: 1, description: '6438 < G ≤ 6738: 3000×2 + 4300×2' },
        { id: `range-${timestamp}-scs9`, minValue: 6739, maxValue: 7438, result: '가이드레일-120*120*3500 x4개', itemCode: 'GR-SCR-SIDE-3500', itemName: '가이드레일-120*120*3500', quantity: 4, description: '6738 < G ≤ 7438: 3500×4개' },
        { id: `range-${timestamp}-scs10`, minValue: 7439, maxValue: 8600, result: '가이드레일-120*120*4000 x2 + 가이드레일-120*120*4300 x2', itemCode: 'GR-SCR-SIDE-COMBO-4000-4300', itemName: '가이드레일 조합 (120×120×4000+4300)', quantity: 1, description: '7438 < G ≤ 8600: 4000×2 + 4300×2' }
      ],
      currentRevision: 0,
      isFinal: false,
      createdAt: new Date().toISOString().split('T')[0],
      createdBy: '시스템',
      updatedAt: new Date().toISOString().split('T')[0]
    },
    
    // 3. 철재 벽면형 가이드레일 (130×75 규격)
    {
      id: `rule-gr-steel-wall-${timestamp}`,
      ruleCode: 'GUIDE-RAIL-STEEL-WALL',
      ruleName: '가이드레일 품목 선택 (철재-벽면형)',
      category: 'guide-rail',
      subcategory: '철재-벽면형',
      ruleType: 'range',
      description: '철재 벽면형 설치: 가이드레일 130×75 규격, 제작길이(G=H0+250) 구간별 품목 선택 (2방 1SET 기준)',
      inputVariable: 'G',
      status: 'active',
      ranges: [
        { id: `range-${timestamp}-stw1`, minValue: 1219, maxValue: 2438, result: '가이드레일-130*75*2438 x2개', itemCode: 'GR-STL-WALL-2438', itemName: '가이드레일-130*75*2438', quantity: 2, description: '1219 < G ≤ 2438: 130×75×2438 x2개' },
        { id: `range-${timestamp}-stw2`, minValue: 2439, maxValue: 3000, result: '가이드레일-130*75*3000 x2개', itemCode: 'GR-STL-WALL-3000', itemName: '가이드레일-130*75*3000', quantity: 2, description: '2438 < G ≤ 3000: 130×75×3000 x2개' },
        { id: `range-${timestamp}-stw3`, minValue: 3001, maxValue: 3500, result: '가이드레일-130*75*3500 x2개', itemCode: 'GR-STL-WALL-3500', itemName: '가이드레일-130*75*3500', quantity: 2, description: '3000 < G ≤ 3500: 130×75×3500 x2개' },
        { id: `range-${timestamp}-stw4`, minValue: 3501, maxValue: 4000, result: '가이드레일-130*75*4000 x2개', itemCode: 'GR-STL-WALL-4000', itemName: '가이드레일-130*75*4000', quantity: 2, description: '3500 < G ≤ 4000: 130×75×4000 x2개' },
        { id: `range-${timestamp}-stw5`, minValue: 4001, maxValue: 4300, result: '가이드레일-130*75*4300 x2개', itemCode: 'GR-STL-WALL-4300', itemName: '가이드레일-130*75*4300', quantity: 2, description: '4000 < G ≤ 4300: 130×75×4300 x2개' },
        { id: `range-${timestamp}-stw6`, minValue: 4301, maxValue: 5438, result: '가이드레일-130*75*3000 x2 + 가이드레일-130*75*3500 x2', itemCode: 'GR-STL-WALL-COMBO-3000-3500', itemName: '가이드레일 조합 (130×75×3000+3500)', quantity: 1, description: '4300 < G ≤ 5438: 3000×2 + 3500×2' },
        { id: `range-${timestamp}-stw7`, minValue: 5439, maxValue: 6438, result: '가이드레일-130*75*3000 x2 + 가이드레일-130*75*4000 x2', itemCode: 'GR-STL-WALL-COMBO-3000-4000', itemName: '가이드레일 조합 (130×75×3000+4000)', quantity: 1, description: '5438 < G ≤ 6438: 3000×2 + 4000×2' },
        { id: `range-${timestamp}-stw8`, minValue: 6439, maxValue: 6738, result: '가이드레일-130*75*3000 x2 + 가이드레일-130*75*4300 x2', itemCode: 'GR-STL-WALL-COMBO-3000-4300', itemName: '가이드레일 조합 (130×75×3000+4300)', quantity: 1, description: '6438 < G ≤ 6738: 3000×2 + 4300×2' },
        { id: `range-${timestamp}-stw9`, minValue: 6739, maxValue: 7438, result: '가이드레일-130*75*3500 x4개', itemCode: 'GR-STL-WALL-3500', itemName: '가이드레일-130*75*3500', quantity: 4, description: '6738 < G ≤ 7438: 3500×4개' },
        { id: `range-${timestamp}-stw10`, minValue: 7439, maxValue: 8600, result: '가이드레일-130*75*4000 x2 + 가이드레일-130*75*4300 x2', itemCode: 'GR-STL-WALL-COMBO-4000-4300', itemName: '가이드레일 조합 (130×75×4000+4300)', quantity: 1, description: '7438 < G ≤ 8600: 4000×2 + 4300×2' }
      ],
      currentRevision: 0,
      isFinal: false,
      createdAt: new Date().toISOString().split('T')[0],
      createdBy: '시스템',
      updatedAt: new Date().toISOString().split('T')[0]
    },
    
    // 4. 철재 측면형 가이드레일 (130×125 규격)
    {
      id: `rule-gr-steel-side-${timestamp}`,
      ruleCode: 'GUIDE-RAIL-STEEL-SIDE',
      ruleName: '가이드레일 품목 선택 (철재-측면형)',
      category: 'guide-rail',
      subcategory: '철재-측면형',
      ruleType: 'range',
      description: '철재 측면형 설치: 가이드레일 130×125 규격, 제작길이(G=H0+250) 구간별 품목 선택 (2방 1SET 기준)',
      inputVariable: 'G',
      status: 'active',
      ranges: [
        { id: `range-${timestamp}-sts1`, minValue: 1219, maxValue: 2438, result: '가이드레일-130*125*2438 x2개', itemCode: 'GR-STL-SIDE-2438', itemName: '가이드레일-130*125*2438', quantity: 2, description: '1219 < G ≤ 2438: 130×125×2438 x2개' },
        { id: `range-${timestamp}-sts2`, minValue: 2439, maxValue: 3000, result: '가이드레일-130*125*3000 x2개', itemCode: 'GR-STL-SIDE-3000', itemName: '가이드레일-130*125*3000', quantity: 2, description: '2438 < G ≤ 3000: 130×125×3000 x2개' },
        { id: `range-${timestamp}-sts3`, minValue: 3001, maxValue: 3500, result: '가이드레일-130*125*3500 x2개', itemCode: 'GR-STL-SIDE-3500', itemName: '가이드레일-130*125*3500', quantity: 2, description: '3000 < G ≤ 3500: 130×125×3500 x2개' },
        { id: `range-${timestamp}-sts4`, minValue: 3501, maxValue: 4000, result: '가이드레일-130*125*4000 x2개', itemCode: 'GR-STL-SIDE-4000', itemName: '가이드레일-130*125*4000', quantity: 2, description: '3500 < G ≤ 4000: 130×125×4000 x2개' },
        { id: `range-${timestamp}-sts5`, minValue: 4001, maxValue: 4300, result: '가이드레일-130*125*4300 x2개', itemCode: 'GR-STL-SIDE-4300', itemName: '가이드레일-130*125*4300', quantity: 2, description: '4000 < G ≤ 4300: 130×125×4300 x2개' },
        { id: `range-${timestamp}-sts6`, minValue: 4301, maxValue: 5438, result: '가이드레일-130*125*3000 x2 + 가이드레일-130*125*3500 x2', itemCode: 'GR-STL-SIDE-COMBO-3000-3500', itemName: '가이드레일 조합 (130×125×3000+3500)', quantity: 1, description: '4300 < G ≤ 5438: 3000×2 + 3500×2' },
        { id: `range-${timestamp}-sts7`, minValue: 5439, maxValue: 6438, result: '가이드레일-130*125*3000 x2 + 가이드레일-130*125*4000 x2', itemCode: 'GR-STL-SIDE-COMBO-3000-4000', itemName: '가이드레일 조합 (130×125×3000+4000)', quantity: 1, description: '5438 < G ≤ 6438: 3000×2 + 4000×2' },
        { id: `range-${timestamp}-sts8`, minValue: 6439, maxValue: 6738, result: '가이드레일-130*125*3000 x2 + 가이드레일-130*125*4300 x2', itemCode: 'GR-STL-SIDE-COMBO-3000-4300', itemName: '가이드레일 조합 (130×125×3000+4300)', quantity: 1, description: '6438 < G ≤ 6738: 3000×2 + 4300×2' },
        { id: `range-${timestamp}-sts9`, minValue: 6739, maxValue: 7438, result: '가이드레일-130*125*3500 x4개', itemCode: 'GR-STL-SIDE-3500', itemName: '가이드레일-130*125*3500', quantity: 4, description: '6738 < G ≤ 7438: 3500×4개' },
        { id: `range-${timestamp}-sts10`, minValue: 7439, maxValue: 8600, result: '가이드레일-130*125*4000 x2 + 가이드레일-130*125*4300 x2', itemCode: 'GR-STL-SIDE-COMBO-4000-4300', itemName: '가이드레일 조합 (130×125×4000+4300)', quantity: 1, description: '7438 < G ≤ 8600: 4000×2 + 4300×2' }
      ],
      currentRevision: 0,
      isFinal: false,
      createdAt: new Date().toISOString().split('T')[0],
      createdBy: '시스템',
      updatedAt: new Date().toISOString().split('T')[0]
    },
    
    // 5. 하부 Base 기준 (스크린 벽면형: 130×80)
    {
      id: `rule-base-screen-wall-${timestamp}`,
      ruleCode: 'BASE-SCREEN-WALL',
      ruleName: '하부 Base (스크린-벽면형)',
      category: 'guide-rail',
      subcategory: '하부Base-스크린-벽면형',
      ruleType: 'fixed',
      description: '스크린 벽면형 설치 시 하부 Base 수량 (130×80 규격, 고정 2EA)',
      fixedValue: 2,
      unit: 'EA',
      itemCode: 'BASE-SCR-WALL',
      itemName: '하부 Base (스크린-벽면형) 130*80',
      status: 'active',
      currentRevision: 0,
      isFinal: false,
      createdAt: new Date().toISOString().split('T')[0],
      createdBy: '시스템',
      updatedAt: new Date().toISOString().split('T')[0]
    },
    
    // 6. 하부 Base 기준 (스크린 측면형: 130×130)
    {
      id: `rule-base-screen-side-${timestamp}`,
      ruleCode: 'BASE-SCREEN-SIDE',
      ruleName: '하부 Base (스크린-측면형)',
      category: 'guide-rail',
      subcategory: '하부Base-스크린-측면형',
      ruleType: 'fixed',
      description: '스크린 측면형 설치 시 하부 Base 수량 (130×130 규격, 고정 2EA)',
      fixedValue: 2,
      unit: 'EA',
      itemCode: 'BASE-SCR-SIDE',
      itemName: '하부 Base (스크린-측면형) 130*130',
      status: 'active',
      currentRevision: 0,
      isFinal: false,
      createdAt: new Date().toISOString().split('T')[0],
      createdBy: '시스템',
      updatedAt: new Date().toISOString().split('T')[0]
    },
    
    // 7. 하부 Base 기준 (철재 벽면형: 140×85)
    {
      id: `rule-base-steel-wall-${timestamp}`,
      ruleCode: 'BASE-STEEL-WALL',
      ruleName: '하부 Base (철재-벽면형)',
      category: 'guide-rail',
      subcategory: '하부Base-철재-벽면형',
      ruleType: 'fixed',
      description: '철재 벽면형 설치 시 하부 Base 수량 (140×85 규격, 고정 2EA)',
      fixedValue: 2,
      unit: 'EA',
      itemCode: 'BASE-STL-WALL',
      itemName: '하부 Base (철재-벽면형) 140*85',
      status: 'active',
      currentRevision: 0,
      isFinal: false,
      createdAt: new Date().toISOString().split('T')[0],
      createdBy: '시스템',
      updatedAt: new Date().toISOString().split('T')[0]
    },
    
    // 8. 하부 Base 기준 (철재 측면형: 140×135)
    {
      id: `rule-base-steel-side-${timestamp}`,
      ruleCode: 'BASE-STEEL-SIDE',
      ruleName: '하부 Base (철재-측면형)',
      category: 'guide-rail',
      subcategory: '하부Base-철재-측면형',
      ruleType: 'fixed',
      description: '철재 측면형 설치 시 하부 Base 수량 (140×135 규격, 고정 2EA)',
      fixedValue: 2,
      unit: 'EA',
      itemCode: 'BASE-STL-SIDE',
      itemName: '하부 Base (철재-측면형) 140*135',
      status: 'active',
      currentRevision: 0,
      isFinal: false,
      createdAt: new Date().toISOString().split('T')[0],
      createdBy: '시스템',
      updatedAt: new Date().toISOString().split('T')[0]
    }
  ];
}
