// Shared TypeScript types mirroring the backend data models

export interface User {
  telegram_id: number;
  username: string;
  display_name: string;
  personality: Personality;
  voice_id: string;
  created_at: string;
}

export type Personality =
  | "aggressive"
  | "people_pleaser"
  | "analytical"
  | "empathetic"
  | "balanced";

export type NegotiationStatus = "pending" | "active" | "resolved" | "escalated";

export type FeatureType =
  | "scheduling"
  | "expenses"
  | "freelance"
  | "roommate"
  | "trip"
  | "marketplace"
  | "collaborative"
  | "conflict"
  | "generic";

export interface Participant {
  negotiation_id: string;
  user_id: number;
  preferences: Record<string, unknown>;
  personality_used: Personality;
  username?: string;
  display_name?: string;
  personality?: Personality;
  voice_id?: string;
}

export interface Round {
  id: number;
  negotiation_id: string;
  round_number: number;
  proposer_id: number;
  proposal: Record<string, unknown>;
  response_type: "propose" | "counter" | "accept" | "escalate";
  response: Record<string, unknown> | null;
  reasoning: string;
  satisfaction_a: number;
  satisfaction_b: number;
  concessions_made: string[];
  created_at: string;
}

export interface SatisfactionPoint {
  round: number;
  score_a: number;
  score_b: number;
}

export interface ConcessionEntry {
  round: number;
  by: "A" | "B";
  gave_up: string;
}

export interface Analytics {
  negotiation_id: string;
  satisfaction_timeline: SatisfactionPoint[];
  concession_log: ConcessionEntry[];
  fairness_score: number;
  total_concessions_a: number;
  total_concessions_b: number;
  computed_at: string;
}

export interface Negotiation {
  id: string;
  feature_type: FeatureType;
  status: NegotiationStatus;
  initiator_id: number;
  resolution: Record<string, unknown> | null;
  voice_summary_file: string | null;
  created_at: string;
  updated_at: string;
  participant_count?: number;
  // Only present in detail view
  participants?: Participant[];
  rounds?: Round[];
  analytics?: Analytics;
}

export interface Stats {
  total_negotiations: number;
  resolved: number;
  active: number;
  escalated: number;
  total_users: number;
  avg_fairness_score: number;
  feature_breakdown: { feature_type: FeatureType; c: number }[];
}
