/**
 * Scene Slot Bundle Types.
 * [AC-SCENE-SLOT-01] 场景-槽位映射配置类型定义
 */

export type SceneSlotBundleStatus = 'draft' | 'active' | 'deprecated'
export type AskBackOrder = 'priority' | 'required_first' | 'parallel'

export interface SceneSlotBundle {
  id: string
  tenant_id: string
  scene_key: string
  scene_name: string
  description: string | null
  required_slots: string[]
  optional_slots: string[]
  slot_priority: string[] | null
  completion_threshold: number
  ask_back_order: AskBackOrder
  status: SceneSlotBundleStatus
  version: number
  created_at: string | null
  updated_at: string | null
}

export interface SlotDetail {
  slot_key: string
  type: string
  required: boolean
  ask_back_prompt: string | null
  linked_field_id: string | null
}

export interface SceneSlotBundleWithDetails extends SceneSlotBundle {
  required_slot_details: SlotDetail[]
  optional_slot_details: SlotDetail[]
}

export interface SceneSlotBundleCreateRequest {
  scene_key: string
  scene_name: string
  description?: string
  required_slots?: string[]
  optional_slots?: string[]
  slot_priority?: string[]
  completion_threshold?: number
  ask_back_order?: AskBackOrder
  status?: SceneSlotBundleStatus
}

export interface SceneSlotBundleUpdateRequest {
  scene_name?: string
  description?: string
  required_slots?: string[]
  optional_slots?: string[]
  slot_priority?: string[]
  completion_threshold?: number
  ask_back_order?: AskBackOrder
  status?: SceneSlotBundleStatus
}

export const SCENE_SLOT_BUNDLE_STATUS_OPTIONS = [
  { value: 'draft', label: '草稿', description: '配置中，未启用' },
  { value: 'active', label: '已启用', description: '运行时可用' },
  { value: 'deprecated', label: '已废弃', description: '不再使用' },
]

export const ASK_BACK_ORDER_OPTIONS = [
  { value: 'priority', label: '按优先级', description: '按 slot_priority 定义的顺序追问' },
  { value: 'required_first', label: '必填优先', description: '优先追问必填槽位' },
  { value: 'parallel', label: '并行追问', description: '一次追问多个缺失槽位' },
]

export function getStatusLabel(status: SceneSlotBundleStatus): string {
  return SCENE_SLOT_BUNDLE_STATUS_OPTIONS.find(o => o.value === status)?.label || status
}

export function getAskBackOrderLabel(order: AskBackOrder): string {
  return ASK_BACK_ORDER_OPTIONS.find(o => o.value === order)?.label || order
}
