import type { BaseEntity } from "../common";

export * from "./support-chat";

export enum TicketStatus {
  Reserved = "RESERVED",
  Confirmed = "CONFIRMED",
  CheckedIn = "CHECKED_IN",
  Cancelled = "CANCELLED",
  Refunded = "REFUNDED",
  Expired = "EXPIRED",
}

export enum SeatClass {
  Economy = "ECONOMY",
  Business = "BUSINESS",
  First = "FIRST",
  Sleeper = "SLEEPER",
}

export enum SeatStatus {
  Available = "AVAILABLE",
  Reserved = "RESERVED",
  Occupied = "OCCUPIED",
  Blocked = "BLOCKED",
}

export enum ScheduleStatus {
  Scheduled = "SCHEDULED",
  Boarding = "BOARDING",
  Departed = "DEPARTED",
  Arrived = "ARRIVED",
  Cancelled = "CANCELLED",
  Delayed = "DELAYED",
}

/**
 * Why a /search leg (outbound or inbound) came back with zero bookable schedules.
 * Priority order applied by the API when classifying: NoRoute > NoScheduleOnDate >
 * Cancelled > PackageOnly > CheckinClosed > FullyBooked (see search.service.ts
 * classifyEmptySearch). The frontend uses this to show a specific empty-state
 * message instead of a generic "no trains available".
 */
export enum SearchEmptyReasonCode {
  /** No route (in either direction) ever connects these two stations. */
  NoRoute = "NO_ROUTE",
  /** A route connects these stations, but no schedule lands on the requested date at all. */
  NoScheduleOnDate = "NO_SCHEDULE_ON_DATE",
  /** Every schedule for this pair on this date was cancelled. */
  Cancelled = "CANCELLED",
  /** Every schedule for this pair on this date is package-only (excluded from ticket search). */
  PackageOnly = "PACKAGE_ONLY",
  /** A bookable schedule exists, but its check-in cutoff has already passed for every option. */
  CheckinClosed = "CHECKIN_CLOSED",
  /** A bookable, still-open schedule exists but has no seats left for the requested party. */
  FullyBooked = "FULLY_BOOKED",
}

export interface ISearchEmptyReason {
  code: SearchEmptyReasonCode;
  originStationName: string;
  destinationStationName: string;
}

export enum PaymentStatus {
  Pending = "PENDING",
  Paid = "PAID",
  Failed = "FAILED",
  Refunded = "REFUNDED",
}

export interface IStation extends BaseEntity {
  code: string;
  name: string;
  city: string;
  country: string;
  latitude?: number;
  longitude?: number;
}

export interface ISchedule extends BaseEntity {
  trainCode: string;
  originStationId: string;
  destinationStationId: string;
  departureTime: string;
  arrivalTime: string;
  status: ScheduleStatus;
  basePrice: number;
}

export interface ISeat extends BaseEntity {
  scheduleId: string;
  seatNumber: string;
  seatClass: SeatClass;
  status: SeatStatus;
  price: number;
}

export interface IPassenger extends BaseEntity {
  fullName: string;
  email: string;
  phone: string;
  nationalId?: string;
  dateOfBirth?: string;
}

export interface ITicket extends BaseEntity {
  reference: string;
  passengerId: string;
  scheduleId: string;
  seatId: string;
  status: TicketStatus;
  pricePaid: number;
  issuedAt: string;
}

export interface IPayment extends BaseEntity {
  ticketId: string;
  amount: number;
  currency: string;
  status: PaymentStatus;
  provider: string;
  providerTransactionId?: string;
  paidAt?: string;
}
