// TypeScript types mirroring Go structs from the backend

export interface Condition {
  field: string;
  operator: string;
  value: string;
}

export interface Action {
  provider: string;
  model: string;
  fallback_chain?: string[];
}

export interface RoutingRule {
  id: string;
  tenant_id: string;
  name: string;
  description: string;
  priority: number;
  is_enabled: boolean;
  conditions: Condition[];
  action: Action;
  created_at: string;
  updated_at: string;
}

export interface AuditEntry {
  request_id: string;
  tenant_id: string;
  user_id: string;
  timestamp: string;
  model_requested: string;
  model_used: string;
  provider: string;
  department: string;
  user_role: string;
  prompt_hash: string;
  response_hash: string;
  sensitivity_level: string;
  token_input: number;
  token_output: number;
  token_total: number;
  cost_usd: number;
  latency_ms: number;
  status: string;
  error_type: string;
  pii_entity_count: number;
  stream: boolean;
}

export interface AuditResult {
  data: AuditEntry[];
  total: number;
}

export interface CostSummary {
  key: string;
  total_tokens: number;
  total_cost_usd: number;
  request_count: number;
}

export interface CostResult {
  data: CostSummary[];
}

export interface ApiError {
  error: {
    type: string;
    message: string;
    code?: string;
  };
}

export interface PiiEntity {
  type: string;
  start: number;
  end: number;
  confidence: number;
  layer: string;
}

export interface PiiAnalyzeResult {
  anonymized: string;
  entities: PiiEntity[];
}

export interface ProviderStatus {
  provider: string;
  state: "closed" | "open" | "half_open";
  failures: number;
  opened_at?: string;
}

export interface ProviderConfig {
  id: string;
  tenant_id: string;
  provider: "openai" | "anthropic" | "azure" | "mistral" | "ollama";
  display_name: string;
  api_key?: string;       // masked on read (e.g. "sk-abc123••••••••"), plaintext on write
  base_url?: string;
  resource_name?: string;
  deployment_id?: string;
  api_version?: string;
  timeout_sec: number;
  max_conns: number;
  model_patterns: string[];
  is_active: boolean;
  created_at: string;
  updated_at: string;
  // enriched by list endpoint
  state?: "closed" | "open" | "half_open";
  failures?: number;
}

export interface CreateProviderRequest {
  provider: "openai" | "anthropic" | "azure" | "mistral" | "ollama";
  display_name?: string;
  api_key?: string;
  base_url?: string;
  resource_name?: string;
  deployment_id?: string;
  api_version?: string;
  timeout_sec?: number;
  max_conns?: number;
  model_patterns?: string[];
  is_active?: boolean;
}

export interface User {
  id: string;
  tenant_id: string;
  email: string;
  name: string;
  department: string;
  role: string;
  is_active: boolean;
  created_at: string;
  updated_at: string;
}

export interface ProcessingEntry {
  id: string;
  use_case_name: string;
  legal_basis: string;
  purpose: string;
  data_categories: string[];
  recipients: string[];
  processors: string[];
  retention_period: string;
  security_measures: string;
  controller_name: string;
  risk_level: "minimal" | "limited" | "high" | "forbidden" | "";
  ai_act_answers?: Record<string, boolean>;
  is_active: boolean;
  created_at: string;
  updated_at: string;
}

export interface GdprAccessResult {
  user_id: string;
  generated_at: string;
  total: number;
  records: AuditEntry[];
}

export interface ErasureResult {
  erasure_id: string;
  user_id: string;
  status: string;
  records_deleted: number;
  timestamp: string;
}
