export type FlightPassengerGroup = {
  id: string;
  adults: number;
  children?: number;
  infants?: number;
  label?: string;
};

export type FlightLegWindow = {
  id: string;
  origin: string;
  destination: string;
  earliest?: string;
  latest?: string;
  relativeToLegId?: string;
  minDaysAfter?: number;
  maxDaysAfter?: number;
  label?: string;
};

export type FlightSearchPreferences = {
  cabin?: "economy" | "premium-economy" | "business" | "first";
  maxStops?: number;
  preferOneStop?: boolean;
  maxLayoverHours?: number;
  excludeAirlines?: string[];
  excludeCountries?: string[];
  excludeAirports?: string[];
  flexibleDates?: boolean;
  requireAirlineDirectCrossCheck?: boolean;
  specialConstraints?: string[];
  geoPricingMarket?: string | null;
  marketCountry?: string | null;
  normalizeCurrencyTo?: "USD";
};

export type FlightReportRequest = {
  tripName?: string;
  legs: FlightLegWindow[];
  passengerGroups: FlightPassengerGroup[];
  legAssignments: Array<{ legId: string; passengerGroupIds: string[] }>;
  recipientEmail?: string | null;
  preferences: FlightSearchPreferences;
};

export type FlightReportStatus = {
  needsMissingInputs: string[];
  readyToSearch: boolean;
  pdfReady: boolean;
  emailReady: boolean;
  lastCompletedPhase?: "intake" | "search" | "ranking" | "render" | "delivery";
};

export type FlightSearchSourceName =
  | "kayak"
  | "skyscanner"
  | "expedia"
  | "airline-direct";

export type FlightSearchSourceViability = "viable" | "degraded" | "blocked";

export type FlightSearchSourceFinding = {
  source: FlightSearchSourceName;
  status: FlightSearchSourceViability;
  checkedAt: string;
  notes: string[];
  evidence?: string[];
};

export type FlightReportRequestDraft = {
  tripName?: string | null;
  legs?: Array<Partial<FlightLegWindow> | null | undefined> | null;
  passengerGroups?: Array<Partial<FlightPassengerGroup> | null | undefined> | null;
  legAssignments?:
    | Array<
        | {
            legId?: string | null;
            passengerGroupIds?: Array<string | null | undefined> | null;
          }
        | null
        | undefined
      >
    | null;
  recipientEmail?: string | null;
  preferences?: Partial<FlightSearchPreferences> | null;
};

export type NormalizedFlightReportRequest = {
  request: FlightReportRequest;
  readyToSearch: boolean;
  missingInputs: string[];
  missingSearchInputs: string[];
  missingDeliveryInputs: string[];
  warnings: string[];
};
