import type { KbxTemplateManifestEntry } from '@kbx/contracts'

const commonA11y=['keyboard','focus-visible','color-independent-state','labelled-regions']
const commonStates=['idle','loading','empty','error','ready'] as const
const desktopUtilities=['help','ai','suggestion'] as const

export const kbxTemplateManifest:KbxTemplateManifestEntry[]=[
  {code:'T01',type:'list',component:'KbxListPage',purpose:'조회·선택·대량처리',requiredSurfaces:['page-header','command-bar','search','content/grid','summary'],optionalSurfaces:['quick-filter','context','bulk-action','detail-drawer'],keyboard:['F3','Ctrl+F'],referenceScreens:['OMS-ORD-001'],defaultDensity:'compact',runtimeStates:[...commonStates],stateCapabilities:['idle','loading','refreshing','empty','error','permission'],utilitySurfaces:[...desktopUtilities],accessibility:[...commonA11y],coreComponents:['KbxSearchPanel','KbxDataGrid','KbxSummaryBar','KbxBulkActionBar'],completionChecks:['조회조건 4~6개 우선 노출','재조회 Context 유지','대량선택 의미 명시','Empty/Error 복구 Action','Drawer 상세로 목록 Context 유지']},
  {code:'T02',type:'master',component:'KbxMasterPage',purpose:'기준정보 목록·상세 CRUD',requiredSurfaces:['page-header','command-bar','detail','record-lifecycle'],optionalSurfaces:['master-list','context','tabs','audit','drawer'],keyboard:['F2','F8','Ctrl+S'],referenceScreens:['ERP-MST-ITEM-001'],defaultDensity:'compact',runtimeStates:[...commonStates],stateCapabilities:['idle','loading','refreshing','empty','error','permission','dirty','conflict'],utilitySurfaces:[...desktopUtilities],accessibility:[...commonA11y],coreComponents:['KbxFormSection','KbxFormGrid','KbxRecordLifecycle','KbxAuditTrail'],completionChecks:['Desktop 기본 2-column Form','신규/수정 권한 분리','Readonly/Disabled 구분','Version 충돌 복구','변경이력 연결']},
  {code:'T03',type:'transaction',component:'KbxTransactionPage',purpose:'Header+Detail 거래 등록·수정',requiredSurfaces:['page-header','command-bar','header-form','detail-grid','summary','record-lifecycle'],optionalSurfaces:['context','workflow','audit','drawer'],keyboard:['F2','F8','Ctrl+S','Enter'],referenceScreens:['OMS-ORD-002','ERP-PUR-001','ERP-INV-MOVE-001'],defaultDensity:'compact',runtimeStates:[...commonStates],stateCapabilities:['loading','refreshing','error','permission','dirty','conflict','validation'],utilitySurfaces:[...desktopUtilities],accessibility:[...commonA11y],coreComponents:['KbxFormSection','KbxFormGrid','KbxDataGrid','KbxSummaryBar','KbxRecordLifecycle'],completionChecks:['Header 2-column Form','Header→Detail Focus 흐름','Dirty 상태에서 위험 Workflow 차단','서버 재검증','Optimistic Concurrency 복구']},
  {code:'T04',type:'fast-entry',component:'KbxFastEntryPage',purpose:'대량 행 입력·붙여넣기',requiredSurfaces:['page-header','command-bar','keyboard-guide','editable-grid','validation','summary'],optionalSurfaces:['context','bulk-action'],keyboard:['Enter','Tab','F2','Ctrl+V','Ctrl+D'],referenceScreens:['ERP-PRICE-001'],defaultDensity:'compact',runtimeStates:[...commonStates],stateCapabilities:['loading','refreshing','error','permission','dirty','validation'],utilitySurfaces:[...desktopUtilities],accessibility:[...commonA11y],coreComponents:['KbxDataGrid','KbxValidationSummary','KbxSummaryBar','KbxLookupDialog'],completionChecks:['다중 Cell Paste 정규화','Fill Down/행 복제','오류 셀 이동','Idempotent Bulk Save','서버 대량 Validation','저장 Command 실패 시 Context 유지·재시도']},
  {code:'T05',type:'master-detail',component:'KbxMasterDetailPage',purpose:'Master 선택 Context 유지 Detail 탐색',requiredSurfaces:['page-header','search','master','detail'],optionalSurfaces:['context','bottom/history','summary','drawer'],keyboard:['F3','Enter'],referenceScreens:['ERP-INV-001'],defaultDensity:'compact',runtimeStates:[...commonStates],stateCapabilities:['idle','loading','refreshing','empty','error','permission'],utilitySurfaces:[...desktopUtilities],accessibility:[...commonA11y],coreComponents:['KbxSearchPanel','KbxDataGrid','KbxTemplateContextBar','KbxDrawer'],completionChecks:['Master 선택 Context 유지','재조회 후 선택 복원','Detail N+1 방지','Drill-down 근거 제공','Drawer로 조회 Context 유지','업무 Action 실패 시 인라인 Problem 복구']},
  {code:'T06',type:'queue',component:'KbxQueuePage',purpose:'지금 처리할 업무·예외 우선 Queue',requiredSurfaces:['page-header','command-bar','work-summary','queue/content'],optionalSurfaces:['search','exceptions','context','bulk-action','detail'],keyboard:['F3','Enter'],referenceScreens:['WMS-WORK-001','COMMON-OPS-001'],defaultDensity:'compact',runtimeStates:[...commonStates],stateCapabilities:['idle','loading','refreshing','empty','error','permission'],utilitySurfaces:[...desktopUtilities],accessibility:[...commonA11y],coreComponents:['KbxExceptionSummary','KbxDataGrid','KbxBulkActionBar','KbxExceptionDetailDrawer'],completionChecks:['정상건보다 예외 우선','SLA/지연 식별','Queue 제목·전체건수·표시건수 구분','긴급/미지정 업무 빠른 이동','부분성공 결과','재처리/해결 Action','예외 처리 Audit','배정/해결 실패 시 현재 Queue Context 유지']},
  {code:'T07',type:'reconcile',component:'KbxReconcilePage',purpose:'Expected/Actual/Difference 정합성 비교·해결',requiredSurfaces:['page-header','criteria/search','summary','comparison-grid'],optionalSurfaces:['filters','context','resolution-action','audit','detail'],keyboard:['F3','Enter'],referenceScreens:['COMMON-REC-001'],defaultDensity:'compact',runtimeStates:[...commonStates],stateCapabilities:['idle','loading','refreshing','empty','error','permission'],utilitySurfaces:[...desktopUtilities],accessibility:[...commonA11y],coreComponents:['KbxSearchPanel','KbxDataGrid','KbxSummaryBar','KbxAuditTrail'],completionChecks:['Expected/Actual/Difference 동시 제공','전체/불일치/확인중/해결 빠른 필터','행 단위 근거 Detail로 비교 Context 유지','원인/해결상태 제공','해결 Action 권한 검증','Audit 연결','해결 Command 실패 시 선택/대사 Context 유지']},
  {code:'T08',type:'import',component:'KbxImportPage',purpose:'파일→매핑→검증→반영 Import',requiredSurfaces:['page-header','progress-steps','import-content','result'],optionalSurfaces:['context','job-progress','footer'],keyboard:['Enter','Esc'],referenceScreens:['OMS-ORD-003'],defaultDensity:'compact',runtimeStates:[...commonStates],stateCapabilities:['loading','refreshing','error','permission','validation','job'],utilitySurfaces:[...desktopUtilities],accessibility:[...commonA11y],coreComponents:['KbxProgressSteps','KbxExcelImport','KbxValidationSummary','KbxJobProgress'],completionChecks:['파일→매핑→검증→미리보기→반영→결과 6단계 고정','Staging 후 Commit','Preview에서 정상/오류/경고·신규/수정 근거 확인','첫/다음 오류 Focus 이동·오류행 다운로드','부분성공 정책 명시','대량 작업 Job 복구','Upload/Mapping/Commit 실패 인라인 복구']},
  {code:'T09',type:'wms-mobile',component:'KbxWmsMobilePage',purpose:'Scanner/PDA 한 손 현장 작업',requiredSurfaces:['mobile-header','network-state','instruction/content','sticky-actions'],optionalSurfaces:['progress','notice','task-context'],keyboard:['Scanner Enter','Esc'],referenceScreens:['WMS-PICK-001','WMS-REC-001','WMS-PUT-001','WMS-COUNT-001'],defaultDensity:'touch',runtimeStates:[...commonStates],stateCapabilities:['loading','refreshing','error','permission','network'],utilitySurfaces:['help'],accessibility:[...commonA11y],coreComponents:['KbxBarcodeCapture','KbxNetworkIndicator','KbxWmsActionButton'],completionChecks:['Touch Density 최소 Target 준수','스캔 가능/차단/서버확인 상태 명시','최근 서버 확인 Scan과 로컬 입력 구분','서버 응답 전 성공 Feedback 금지','중복 Scan Idempotency','오프라인 정책 명시','오류 시 다음 행동 우선']},
]

export function getKbxTemplate(type:KbxTemplateManifestEntry['type']){return kbxTemplateManifest.find(entry=>entry.type===type)}
