import type { MetadataPayload } from '@/types/metadata'

export interface ScriptFlow {
  id: string
  name: string
  description?: string
  step_count: number
  is_enabled: boolean
  linked_rule_count: number
  metadata?: MetadataPayload
  created_at: string
  updated_at: string
}

export interface ScriptFlowDetail {
  id: string
  name: string
  description?: string
  steps: FlowStep[]
  is_enabled: boolean
  metadata?: MetadataPayload
  created_at: string
  updated_at: string
}

export type ScriptMode = 'fixed' | 'flexible' | 'template'

export interface FlowStep {
  step_id: string
  step_no: number
  content: string
  wait_input: boolean
  timeout_seconds?: number
  timeout_action?: 'repeat' | 'skip' | 'transfer'
  next_conditions?: NextCondition[]
  default_next?: number
  script_mode?: ScriptMode
  intent?: string
  intent_description?: string
  script_constraints?: string[]
  expected_variables?: string[]
  allowed_kb_ids?: string[]
  preferred_kb_ids?: string[]
  kb_query_hint?: string
  max_kb_calls_per_step?: number
}

export interface NextCondition {
  keywords?: string[]
  pattern?: string
  goto_step: number
}

export interface ScriptFlowCreate {
  name: string
  description?: string
  steps: FlowStep[]
  is_enabled?: boolean
  metadata?: MetadataPayload
}

export interface ScriptFlowUpdate {
  name?: string
  description?: string
  steps?: FlowStep[]
  is_enabled?: boolean
  metadata?: MetadataPayload
}

export interface ScriptFlowListResponse {
  data: ScriptFlow[]
}

export const TIMEOUT_ACTION_OPTIONS = [
  { value: 'repeat', label: '重复当前步骤' },
  { value: 'skip', label: '跳过进入下一步' },
  { value: 'transfer', label: '转人工' }
]

export const SCRIPT_MODE_OPTIONS = [
  { value: 'fixed' as const, label: '固定话术', description: '话术内容固定不变' },
  { value: 'flexible' as const, label: '灵活话术', description: 'AI根据意图和上下文生成' },
  { value: 'template' as const, label: '模板话术', description: 'AI填充模板中的变量' }
]

export const PRESET_CONSTRAINTS = [
  '必须礼貌',
  '语气自然',
  '简洁明了',
  '不要生硬',
  '不要重复'
]
