export type KbxAiCapability = 'explain' | 'suggest' | 'draft' | 'execute'

export interface KbxAiScreenContext {
  screenId: string
  screenVersion: string
  entityId?: string
  selectedIds?: string[]
  filters?: Record<string, unknown>
  allowedCapabilities: KbxAiCapability[]
}

export interface KbxAiEvidence {
  label: string
  sourceType: 'domain' | 'api' | 'audit' | 'document' | 'rule'
  reference?: string
}

export interface KbxAiProposalChange {
  field: string
  label: string
  before?: unknown
  after?: unknown
}

export type KbxAiProposalValidationState = 'pending' | 'validated' | 'invalid' | 'stale'

export interface KbxAiProposalValidation {
  state: KbxAiProposalValidationState
  message?: string
  validatedAt?: string
}

export interface KbxAiProposal {
  id: string
  type: string
  title: string
  explanation: string
  capability: Exclude<KbxAiCapability, 'explain'>
  targets?: { entityType: string; entityId: string }[]
  proposedChanges?: KbxAiProposalChange[]
  evidence?: KbxAiEvidence[]
  confidence?: number
  requiredPermission?: string
  validation?: KbxAiProposalValidation
}

export interface KbxAiAskRequest {
  question: string
  context: KbxAiScreenContext
}

export interface KbxAiAnswerAction {
  id: string
  label: string
  kind: 'navigate' | 'filter' | 'proposal'
  requiredCapability?: KbxAiCapability
  requiredPermission?: string
}

export interface KbxAiAnswer {
  answer: string
  actions?: KbxAiAnswerAction[]
  proposal?: KbxAiProposal
  evidence?: KbxAiEvidence[]
}
