// 수주기준 Config - 방화셔터 제조용
// 현재 수주관리 화면의 실제 필드 기반
const orderMasterConfig = {
  id: 'order',
  title: '수주기준 목록',
  description: '수주 템플릿과 필드를 관리합니다',
  icon: 'Package',
  tabs: [
    { id: 'hierarchy', label: '계층구조', icon: 'GitBranch' },
    { id: 'section', label: '섹션', icon: 'Layers' },
    { id: 'field', label: '항목', icon: 'ClipboardList' },
    { id: 'attribute', label: '속성', icon: 'Settings' },
  ],
  // 수주 유형
  entityTypes: [
    { id: 1, code: 'NORMAL', name: '일반수주', description: '견적 기반 일반 수주', sortOrder: 1, isActive: true },
    { id: 2, code: 'ADDITIONAL', name: '추가수주', description: '기존 수주 추가분', sortOrder: 2, isActive: true },
    { id: 3, code: 'DIRECT', name: '직접수주', description: '견적 없이 직접 입력', sortOrder: 3, isActive: true },
  ],
  // 제품 카테고리 (생산공정 분류)
  categories: [
    { id: 1, code: 'SCREEN', name: '스크린', parentId: null, level: 1, path: '/1', sortOrder: 1 },
    { id: 2, code: 'FOLD', name: '절곡', parentId: null, level: 1, path: '/2', sortOrder: 2 },
    { id: 3, code: 'SLAT', name: '슬랫', parentId: null, level: 1, path: '/3', sortOrder: 3 },
    { id: 4, code: 'ASSY', name: '조립', parentId: null, level: 1, path: '/4', sortOrder: 4 },
  ],
  masterFields: [
    // 기본정보 섹션
    { id: 1, fieldKey: 'orderNo', fieldName: '수주번호', inputType: 'text', isRequired: true, isAutoGenerate: true, description: '수주 식별 번호 (자동생성)' },
    { id: 2, fieldKey: 'orderDate', fieldName: '수주일', inputType: 'date', isRequired: true, description: '수주 등록일' },
    { id: 3, fieldKey: 'quoteNo', fieldName: '견적번호', inputType: 'text', isRequired: false, description: '연결된 견적번호' },
    { id: 4, fieldKey: 'customerName', fieldName: '거래처명', inputType: 'text', isRequired: true, description: '거래처명' },
    { id: 5, fieldKey: 'customerId', fieldName: '거래처ID', inputType: 'text', isRequired: false, description: '거래처 식별자' },
    { id: 6, fieldKey: 'siteName', fieldName: '현장명', inputType: 'text', isRequired: true, description: '설치 현장명' },
    { id: 7, fieldKey: 'manager', fieldName: '담당자', inputType: 'text', isRequired: false, description: '거래처 담당자' },
    { id: 8, fieldKey: 'contact', fieldName: '연락처', inputType: 'text', isRequired: false, description: '담당자 연락처' },

    // 납품정보 섹션
    { id: 10, fieldKey: 'dueDate', fieldName: '납기일', inputType: 'date', isRequired: true, description: '납품 예정일' },
    { id: 11, fieldKey: 'deliveryMethod', fieldName: '배송방법', inputType: 'select', isRequired: false, options: { items: ['직접배차', '상차', '택배', '화물', '직접배송'] }, description: '배송 방법' },
    { id: 12, fieldKey: 'deliveryAddress', fieldName: '납품주소', inputType: 'text', isRequired: false, description: '납품 주소' },
    { id: 13, fieldKey: 'receiverName', fieldName: '수령자명', inputType: 'text', isRequired: false, description: '현장 수령자' },
    { id: 14, fieldKey: 'receiverPhone', fieldName: '수령자연락처', inputType: 'text', isRequired: false, description: '수령자 연락처' },

    // 품목정보 (다중행)
    { id: 20, fieldKey: 'productCode', fieldName: '품목코드', inputType: 'text', isRequired: false, description: '품목 코드' },
    { id: 21, fieldKey: 'productName', fieldName: '품목명', inputType: 'select', isRequired: true, options: { items: ['국민방화스크린셔터', '방화셔터', '방연셔터'] }, description: '품목명' },
    { id: 22, fieldKey: 'category', fieldName: '카테고리', inputType: 'select', isRequired: false, options: { items: ['스크린', '절곡', '슬랫', '조립'] }, description: '생산 공정 분류' },
    { id: 23, fieldKey: 'floor', fieldName: '층', inputType: 'text', isRequired: false, description: '설치 층' },
    { id: 24, fieldKey: 'location', fieldName: '위치', inputType: 'text', isRequired: false, description: '설치 위치' },
    { id: 25, fieldKey: 'openWidth', fieldName: '개구폭(mm)', inputType: 'number', isRequired: true, validations: { min: 500, max: 15000 }, description: '개구부 폭' },
    { id: 26, fieldKey: 'openHeight', fieldName: '개구높이(mm)', inputType: 'number', isRequired: true, validations: { min: 500, max: 10000 }, description: '개구부 높이' },
    { id: 27, fieldKey: 'qty', fieldName: '수량', inputType: 'number', isRequired: true, validations: { min: 1 }, description: '주문 수량' },
    { id: 28, fieldKey: 'unitPrice', fieldName: '단가', inputType: 'number', isRequired: false, description: '제품 단가' },
    { id: 29, fieldKey: 'amount', fieldName: '금액', inputType: 'number', isRequired: false, isCalculated: true, description: '수량 × 단가' },

    // 제작사양 (자동계산)
    { id: 30, fieldKey: 'prodWidth', fieldName: '제작폭(mm)', inputType: 'number', isRequired: false, isCalculated: true, description: '개구폭 + 140' },
    { id: 31, fieldKey: 'prodHeight', fieldName: '제작높이(mm)', inputType: 'number', isRequired: false, isCalculated: true, description: 'MAX(개구높이+400, 2950)' },
    { id: 32, fieldKey: 'guideRailType', fieldName: '가이드레일형태', inputType: 'select', isRequired: false, options: { items: ['백면형', '양면형', '편면형'] }, description: '가이드레일 형태' },
    { id: 33, fieldKey: 'guideRailSpec', fieldName: '가이드레일규격', inputType: 'select', isRequired: false, options: { items: ['120-70', '150-80', '180-90'] }, description: '가이드레일 규격' },
    { id: 34, fieldKey: 'finish', fieldName: '마감', inputType: 'select', isRequired: false, options: { items: ['SUS마감', '분체도장', '용융아연'] }, description: '마감 처리' },
    { id: 35, fieldKey: 'shaft', fieldName: '샤프트', inputType: 'number', isRequired: false, isCalculated: true, description: '폭>6000:5인치, 그외:4인치' },
    { id: 36, fieldKey: 'capacity', fieldName: '전동용량', inputType: 'number', isRequired: false, isCalculated: true, description: '폭>6000:300kg, 그외:160kg' },

    // 금액정보 섹션
    { id: 40, fieldKey: 'totalAmount', fieldName: '총금액', inputType: 'number', isRequired: false, isCalculated: true, description: '품목 금액 합계' },

    // 기타정보 섹션
    { id: 50, fieldKey: 'note', fieldName: '비고', inputType: 'textarea', isRequired: false, description: '특이사항 및 요청사항' },
  ],
  masterSections: [
    { id: 1, sectionKey: 'basicInfo', sectionName: '기본정보', sectionType: 'general', applicableTypes: ['NORMAL', 'ADDITIONAL', 'DIRECT'], description: '수주 기본 정보', fields: [1, 2, 3, 4, 5, 6, 7, 8] },
    { id: 2, sectionKey: 'deliveryInfo', sectionName: '납품정보', sectionType: 'general', applicableTypes: ['NORMAL', 'ADDITIONAL', 'DIRECT'], description: '납품 관련 정보', fields: [10, 11, 12, 13, 14] },
    { id: 3, sectionKey: 'itemInfo', sectionName: '품목정보', sectionType: 'multiRow', applicableTypes: ['NORMAL', 'ADDITIONAL', 'DIRECT'], description: '수주 품목 목록', fields: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29] },
    { id: 4, sectionKey: 'productionSpec', sectionName: '제작사양', sectionType: 'multiRow', applicableTypes: ['NORMAL', 'ADDITIONAL', 'DIRECT'], description: '제작 상세 사양', fields: [30, 31, 32, 33, 34, 35, 36] },
    { id: 5, sectionKey: 'amountInfo', sectionName: '금액정보', sectionType: 'general', applicableTypes: ['NORMAL', 'ADDITIONAL', 'DIRECT'], description: '금액 합계', fields: [40] },
    { id: 6, sectionKey: 'etcInfo', sectionName: '기타정보', sectionType: 'general', applicableTypes: ['NORMAL', 'ADDITIONAL', 'DIRECT'], description: '기타 정보', fields: [50] },
  ],
  pageTemplates: [
    {
      id: 1, pageCode: 'order_normal', pageName: '일반 수주', pagePath: '/판매관리/수주_등록', itemTypes: ['NORMAL'],
      sections: [
        { sectionId: 1, sectionKey: 'basicInfo', sectionName: '기본정보', sortOrder: 1, fields: [
          { fieldId: 1, fieldKey: 'orderNo', fieldName: '수주번호', inputType: 'text', isRequired: true, isAutoGenerate: true },
          { fieldId: 2, fieldKey: 'orderDate', fieldName: '수주일', inputType: 'date', isRequired: true },
          { fieldId: 3, fieldKey: 'quoteNo', fieldName: '견적번호', inputType: 'text', isRequired: false },
          { fieldId: 4, fieldKey: 'customerName', fieldName: '거래처명', inputType: 'text', isRequired: true },
          { fieldId: 6, fieldKey: 'siteName', fieldName: '현장명', inputType: 'text', isRequired: true },
          { fieldId: 7, fieldKey: 'manager', fieldName: '담당자', inputType: 'text', isRequired: false },
          { fieldId: 8, fieldKey: 'contact', fieldName: '연락처', inputType: 'text', isRequired: false },
        ]},
        { sectionId: 2, sectionKey: 'deliveryInfo', sectionName: '납품정보', sortOrder: 2, fields: [
          { fieldId: 10, fieldKey: 'dueDate', fieldName: '납기일', inputType: 'date', isRequired: true },
          { fieldId: 11, fieldKey: 'deliveryMethod', fieldName: '배송방법', inputType: 'select', isRequired: false },
          { fieldId: 12, fieldKey: 'deliveryAddress', fieldName: '납품주소', inputType: 'text', isRequired: false },
          { fieldId: 13, fieldKey: 'receiverName', fieldName: '수령자명', inputType: 'text', isRequired: false },
          { fieldId: 14, fieldKey: 'receiverPhone', fieldName: '수령자연락처', inputType: 'text', isRequired: false },
        ]},
        { sectionId: 3, sectionKey: 'itemInfo', sectionName: '품목정보', sortOrder: 3, isMultiRow: true, fields: [
          { fieldId: 21, fieldKey: 'productName', fieldName: '품목명', inputType: 'select', isRequired: true },
          { fieldId: 22, fieldKey: 'category', fieldName: '카테고리', inputType: 'select', isRequired: false },
          { fieldId: 23, fieldKey: 'floor', fieldName: '층', inputType: 'text', isRequired: false },
          { fieldId: 24, fieldKey: 'location', fieldName: '위치', inputType: 'text', isRequired: false },
          { fieldId: 25, fieldKey: 'openWidth', fieldName: '개구폭', inputType: 'number', isRequired: true },
          { fieldId: 26, fieldKey: 'openHeight', fieldName: '개구높이', inputType: 'number', isRequired: true },
          { fieldId: 27, fieldKey: 'qty', fieldName: '수량', inputType: 'number', isRequired: true },
          { fieldId: 28, fieldKey: 'unitPrice', fieldName: '단가', inputType: 'number', isRequired: false },
          { fieldId: 29, fieldKey: 'amount', fieldName: '금액', inputType: 'number', isRequired: false },
        ]},
        { sectionId: 4, sectionKey: 'productionSpec', sectionName: '제작사양', sortOrder: 4, isMultiRow: true, fields: [
          { fieldId: 32, fieldKey: 'guideRailType', fieldName: '가이드레일형태', inputType: 'select', isRequired: false },
          { fieldId: 33, fieldKey: 'guideRailSpec', fieldName: '가이드레일규격', inputType: 'select', isRequired: false },
          { fieldId: 34, fieldKey: 'finish', fieldName: '마감', inputType: 'select', isRequired: false },
        ]},
        { sectionId: 5, sectionKey: 'amountInfo', sectionName: '금액정보', sortOrder: 5, fields: [
          { fieldId: 40, fieldKey: 'totalAmount', fieldName: '총금액', inputType: 'number', isRequired: false },
        ]},
        { sectionId: 6, sectionKey: 'etcInfo', sectionName: '기타정보', sortOrder: 6, fields: [
          { fieldId: 50, fieldKey: 'note', fieldName: '비고', inputType: 'textarea', isRequired: false },
        ]},
      ],
      conditions: []
    },
    {
      id: 2, pageCode: 'order_additional', pageName: '추가 수주', pagePath: '/판매관리/수주_추가', itemTypes: ['ADDITIONAL'],
      sections: [
        { sectionId: 1, sectionKey: 'basicInfo', sectionName: '기본정보', sortOrder: 1, fields: [
          { fieldId: 1, fieldKey: 'orderNo', fieldName: '수주번호', inputType: 'text', isRequired: true, isAutoGenerate: true },
          { fieldId: 2, fieldKey: 'orderDate', fieldName: '수주일', inputType: 'date', isRequired: true },
          { fieldId: 3, fieldKey: 'quoteNo', fieldName: '원 견적번호', inputType: 'text', isRequired: false },
          { fieldId: 4, fieldKey: 'customerName', fieldName: '거래처명', inputType: 'text', isRequired: true },
          { fieldId: 6, fieldKey: 'siteName', fieldName: '현장명', inputType: 'text', isRequired: true },
        ]},
        { sectionId: 3, sectionKey: 'itemInfo', sectionName: '추가 품목', sortOrder: 2, isMultiRow: true, fields: [
          { fieldId: 21, fieldKey: 'productName', fieldName: '품목명', inputType: 'select', isRequired: true },
          { fieldId: 25, fieldKey: 'openWidth', fieldName: '개구폭', inputType: 'number', isRequired: true },
          { fieldId: 26, fieldKey: 'openHeight', fieldName: '개구높이', inputType: 'number', isRequired: true },
          { fieldId: 27, fieldKey: 'qty', fieldName: '수량', inputType: 'number', isRequired: true },
          { fieldId: 29, fieldKey: 'amount', fieldName: '금액', inputType: 'number', isRequired: false },
        ]},
        { sectionId: 6, sectionKey: 'etcInfo', sectionName: '기타정보', sortOrder: 3, fields: [
          { fieldId: 50, fieldKey: 'note', fieldName: '비고', inputType: 'textarea', isRequired: false },
        ]},
      ],
      conditions: []
    },
  ],
  // 자동계산 규칙
  calculations: [
    { field: 'prodWidth', formula: 'openWidth + 140', description: '제작폭 = 개구폭 + 140' },
    { field: 'prodHeight', formula: 'MAX(openHeight + 400, 2950)', description: '제작높이 = MAX(개구높이+400, 2950)' },
    { field: 'shaft', formula: 'openWidth > 6000 ? 5 : 4', description: '샤프트 인치' },
    { field: 'capacity', formula: 'openWidth > 6000 ? 300 : 160', description: '전동용량 kg' },
    { field: 'amount', formula: 'qty * unitPrice', description: '금액 = 수량 × 단가' },
    { field: 'totalAmount', formula: 'SUM(items.amount)', description: '총금액 = 품목 금액 합계' },
  ],
};

export default orderMasterConfig;
