/**
 * BYOEH (Erwartungshorizont) Types
 *
 * Split from api.ts for file size compliance.
 */

export interface Erwartungshorizont {
  id: string
  tenant_id: string
  teacher_id: string
  title: string
  subject: string
  niveau: 'eA' | 'gA'
  year: number
  aufgaben_nummer: string | null
  status: 'pending_rights' | 'processing' | 'indexed' | 'error'
  chunk_count: number
  rights_confirmed: boolean
  rights_confirmed_at: string | null
  indexed_at: string | null
  file_size_bytes: number
  original_filename: string
  training_allowed: boolean
  created_at: string
  deleted_at: string | null
}

export interface EHRAGResult {
  context: string
  sources: Array<{
    text: string; eh_id: string; eh_title: string;
    chunk_index: number; score: number; reranked?: boolean
  }>
  query: string
  search_info?: {
    retrieval_time_ms?: number; rerank_time_ms?: number; total_time_ms?: number;
    reranked?: boolean; rerank_applied?: boolean; hybrid_search_applied?: boolean;
    embedding_model?: string; total_candidates?: number; original_count?: number
  }
}

export interface EHAuditEntry {
  id: string; eh_id: string | null; tenant_id: string; user_id: string;
  action: string; details: Record<string, unknown> | null; created_at: string
}

export interface EHKeyShare {
  id: string; eh_id: string; user_id: string; passphrase_hint: string;
  granted_by: string; granted_at: string;
  role: 'second_examiner' | 'third_examiner' | 'supervisor' | 'department_head';
  klausur_id: string | null; active: boolean
}

export interface EHKlausurLink {
  id: string; eh_id: string; klausur_id: string;
  linked_by: string; linked_at: string
}

export interface SharedEHInfo { eh: Erwartungshorizont; share: EHKeyShare }

export interface LinkedEHInfo {
  eh: Erwartungshorizont; link: EHKlausurLink;
  is_owner: boolean; share: EHKeyShare | null
}

export interface EHShareInvitation {
  id: string; eh_id: string; inviter_id: string; invitee_id: string;
  invitee_email: string;
  role: 'second_examiner' | 'third_examiner' | 'supervisor' | 'department_head' | 'fachvorsitz';
  klausur_id: string | null; message: string | null;
  status: 'pending' | 'accepted' | 'declined' | 'expired' | 'revoked';
  expires_at: string; created_at: string;
  accepted_at: string | null; declined_at: string | null
}

export interface PendingInvitationInfo {
  invitation: EHShareInvitation
  eh: { id: string; title: string; subject: string; niveau: string; year: number } | null
}

export interface SentInvitationInfo {
  invitation: EHShareInvitation
  eh: { id: string; title: string; subject: string } | null
}

export interface EHAccessChain {
  eh_id: string; eh_title: string;
  owner: { user_id: string; role: string };
  active_shares: EHKeyShare[];
  pending_invitations: EHShareInvitation[];
  revoked_shares: EHKeyShare[]
}
