export const CITATION_STYLES = [
  "APA7",
  "MLA9",
  "CHICAGO17",
  "HARVARD",
  "IEEE",
  "VANCOUVER"
] as const;

export type CitationStyle = (typeof CITATION_STYLES)[number];

export const LLM_PERSONALITIES = [
  "academic_mentor",
  "critical_reviewer",
  "concise_editor",
  "methods_coach",
  "evidence_scout"
] as const;

export type LlmPersonality = (typeof LLM_PERSONALITIES)[number];

export const PROOFREAD_MODES = [
  "proofread",
  "formalize",
  "simplify",
  "shorten",
  "expand",
  "paraphrase",
  "coherence"
] as const;

export type ProofreadMode = (typeof PROOFREAD_MODES)[number];

export interface ProofreadRequest {
  documentId: string;
  text: string;
  mode: ProofreadMode;
  citationStyle?: CitationStyle;
  personality?: LlmPersonality;
}

export interface ProofreadSuggestion {
  id: string;
  issue: string;
  explanation: string;
  originalText: string;
  suggestedText: string;
}

export interface ProofreadResponse {
  mode: ProofreadMode;
  personality: LlmPersonality;
  summary: string;
  suggestions: ProofreadSuggestion[];
}

export const AI_ACTIONS = [
  "summarize",
  "critique",
  "rewrite",
  "add_section"
] as const;

export type AiActionType = (typeof AI_ACTIONS)[number];

export const AI_SCOPES = ["selection", "section", "document"] as const;

export type AiScope = (typeof AI_SCOPES)[number];

export interface SourceCard {
  id: string;
  title: string;
  authors: string[];
  year: number;
  venue?: string;
  doi?: string;
  rationale: string;
}

export interface AiActionRequest {
  documentId: string;
  action: AiActionType;
  scope: AiScope;
  prompt: string;
  selectionText?: string;
  personality?: LlmPersonality;
}

export interface AiActionResponse {
  action: AiActionType;
  personality: LlmPersonality;
  output: {
    text: string;
    grounded: boolean;
  };
  warnings: string[];
  sources: SourceCard[];
}

export const SEARCH_INTENTS = [
  "support",
  "foundational",
  "recent",
  "conflicting"
] as const;

export type SearchIntent = (typeof SEARCH_INTENTS)[number];

export interface SupportClaimRequest {
  claimText: string;
  intent: SearchIntent;
  maxResults: number;
}

export interface ReferenceSearchResult {
  id: string;
  title: string;
  authors: string[];
  year: number;
  venue?: string;
  doi?: string;
  abstractSnippet?: string;
  rationale: string;
  openAccess?: boolean;
}

export interface SupportClaimResponse {
  claimText: string;
  intent: SearchIntent;
  warning?: string;
  results: ReferenceSearchResult[];
}

export const SUPPORT_SOURCE_TYPES = [
  "web_article",
  "blog",
  "peer_reviewed_article",
  "book"
] as const;

export type SupportSourceType = (typeof SUPPORT_SOURCE_TYPES)[number];

export const LLM_PROVIDERS = ["openai", "anthropic"] as const;

export type LlmProvider = (typeof LLM_PROVIDERS)[number];

export interface AuthUser {
  email: string;
  name: string;
  emailVerified: boolean;
}

export interface AuthRequest {
  email: string;
  password: string;
  name?: string;
}

export interface ForgotPasswordRequest {
  email: string;
}

export interface AuthResponse {
  token?: string;
  user: AuthUser;
  requiresVerification?: boolean;
  message: string;
}

export interface ForgotPasswordResponse {
  ok: boolean;
  message: string;
}

export interface VerifyEmailRequest {
  token: string;
}

export interface VerifyEmailResponse {
  ok: boolean;
  message: string;
  user?: AuthUser;
}

export interface ResendVerificationRequest {
  email: string;
}

export interface ResetPasswordRequest {
  token: string;
  password: string;
}

export interface ResetPasswordResponse {
  ok: boolean;
  message: string;
}

export interface SupportBibliographySource {
  id: string;
  type: SupportSourceType;
  title: string;
  authors: string[];
  year: number;
  venue?: string;
  publisher?: string;
  url?: string;
  doi?: string;
  enw: string;
  rationale?: string;
}

export interface LlmSupportClaimRequest {
  claimText: string;
  sourceTypes: SupportSourceType[];
  citationStyle?: CitationStyle;
  personality?: LlmPersonality;
}

export interface LlmSupportClaimResponse {
  claimText: string;
  prompt: string;
  provider: LlmProvider;
  personality: LlmPersonality;
  answerText: string;
  bibliography: SupportBibliographySource[];
  warning?: string;
}

export interface HealthResponse {
  status: "ok";
  service: string;
  timestamp: string;
}

export interface CitationLibrarySource {
  decimalId: number;
  type: string;
  title: string;
  authors: string[];
  journal: string;
  volume: string;
  issue: string;
  pages: string;
  date: string;
  year: number;
  doi: string;
  abstract: string;
  isbn: string;
  publisher: string;
  origin: string;
  fileName: string;
  importedAt: string;
  note: string;
}

export interface ReferenceLibraryResponse {
  libraryPath: string;
  sources: CitationLibrarySource[];
}

export interface ImportEnwRequest {
  fileName: string;
  content: string;
}

export interface ImportEnwResponse extends ReferenceLibraryResponse {
  added: CitationLibrarySource;
}

export interface DeleteLibrarySourceRequest {
  decimalId: number;
}

export type CitationImportFormat = "ris" | "xml" | "enw";

export interface ImportCitationRequest {
  fileName: string;
  content: string;
  format: CitationImportFormat;
}

export interface ImportCitationResponse extends ReferenceLibraryResponse {
  added: CitationLibrarySource;
}

export interface BibliographyRequest {
  sources: CitationLibrarySource[];
  style: CitationStyle;
}

export interface BibliographyResponse {
  style: CitationStyle;
  html: string;
  plain: string;
}

export interface SettingsConfig {
  defaultCitationStyle: CitationStyle;
  crossrefMailto: string;
  openalexEmail: string;
}

export interface SaveSettingsRequest {
  settings: Partial<SettingsConfig>;
}

export interface SettingsResponse {
  settings: SettingsConfig;
}
