/**
 * Shared test fixtures for Online Board integration tests.
 *
 * Provides realistic mock data matching the API response shapes
 * defined in src/features/online-board/types.ts.
 */

import type {
  ISimpleFlight,
  IDirectFlight,
  IMultiLegFlight,
  IFlightLeg,
  IBoardResponse,
} from "@/features/online-board/types.js";

// ---------------------------------------------------------------------------
// Flight leg builder
// ---------------------------------------------------------------------------

function makeLeg(overrides: Partial<IFlightLeg> & { index: number }): IFlightLeg {
  return {
    index: overrides.index,
    status: overrides.status ?? "Scheduled",
    flyingTime: overrides.flyingTime ?? "03:30",
    dayChange: overrides.dayChange ?? 0,
    updated: overrides.updated ?? "2025-01-15T10:00:00Z",
    equipment: overrides.equipment ?? { name: "Boeing 777-300ER", code: "77W" },
    flags: overrides.flags ?? {
      checkinAvailable: true,
      returnToAirport: false,
      routeChanged: false,
    },
    operatingBy: overrides.operatingBy ?? { carrier: "SU", flightNumber: "100" },
    departure: overrides.departure ?? {
      scheduled: {
        airport: "Sheremetyevo",
        airportCode: "SVO",
        city: "Moscow",
        cityCode: "MOW",
        countryCode: "RU",
      },
      checkingStatus: "Open",
      times: {
        scheduledDeparture: {
          dayChange: { value: 0, title: "" },
          local: "10:00",
          localTime: "10:00:00",
          tzOffset: 3,
          utc: "2025-01-15T07:00:00Z",
        },
      },
    },
    arrival: overrides.arrival ?? {
      scheduled: {
        airport: "John F. Kennedy",
        airportCode: "JFK",
        city: "New York",
        cityCode: "NYC",
        countryCode: "US",
      },
      times: {
        scheduledArrival: {
          dayChange: { value: 0, title: "" },
          local: "13:30",
          localTime: "13:30:00",
          tzOffset: -5,
          utc: "2025-01-15T18:30:00Z",
        },
      },
    },
  };
}

// ---------------------------------------------------------------------------
// Flight fixtures
// ---------------------------------------------------------------------------

export const DIRECT_FLIGHT: IDirectFlight = {
  id: "SU100-20250115",
  flightId: {
    carrier: "SU",
    flightNumber: "0100",
    suffix: "",
    date: "20250115",
  },
  routeType: "Direct",
  status: "Scheduled",
  flyingTime: "10:30",
  operatingBy: { carrier: "SU", flightNumber: "100" },
  leg: makeLeg({ index: 0 }),
};

export const DIRECT_FLIGHT_2: IDirectFlight = {
  id: "SU200-20250115",
  flightId: {
    carrier: "SU",
    flightNumber: "0200",
    suffix: "",
    date: "20250115",
  },
  routeType: "Direct",
  status: "InFlight",
  flyingTime: "04:15",
  operatingBy: { carrier: "SU", flightNumber: "200" },
  leg: makeLeg({
    index: 0,
    status: "InFlight",
    departure: {
      scheduled: {
        airport: "Sheremetyevo",
        airportCode: "SVO",
        city: "Moscow",
        cityCode: "MOW",
        countryCode: "RU",
      },
      checkingStatus: "Closed",
      times: {
        scheduledDeparture: {
          dayChange: { value: 0, title: "" },
          local: "08:00",
          localTime: "08:00:00",
          tzOffset: 3,
          utc: "2025-01-15T05:00:00Z",
        },
      },
    },
    arrival: {
      scheduled: {
        airport: "Pulkovo",
        airportCode: "LED",
        city: "Saint Petersburg",
        cityCode: "LED",
        countryCode: "RU",
      },
      times: {
        scheduledArrival: {
          dayChange: { value: 0, title: "" },
          local: "09:30",
          localTime: "09:30:00",
          tzOffset: 3,
          utc: "2025-01-15T06:30:00Z",
        },
      },
    },
  }),
};

export const MULTI_LEG_FLIGHT: IMultiLegFlight = {
  id: "SU300-20250115",
  flightId: {
    carrier: "SU",
    flightNumber: "0300",
    suffix: "",
    date: "20250115",
  },
  routeType: "MultiLeg",
  status: "Scheduled",
  flyingTime: "14:00",
  operatingBy: { carrier: "SU", flightNumber: "300" },
  legs: [
    makeLeg({ index: 0 }),
    makeLeg({
      index: 1,
      departure: {
        scheduled: {
          airport: "John F. Kennedy",
          airportCode: "JFK",
          city: "New York",
          cityCode: "NYC",
          countryCode: "US",
        },
        checkingStatus: "Open",
        times: {
          scheduledDeparture: {
            dayChange: { value: 0, title: "" },
            local: "16:00",
            localTime: "16:00:00",
            tzOffset: -5,
            utc: "2025-01-15T21:00:00Z",
          },
        },
      },
      arrival: {
        scheduled: {
          airport: "Heathrow",
          airportCode: "LHR",
          city: "London",
          cityCode: "LON",
          countryCode: "GB",
        },
        times: {
          scheduledArrival: {
            dayChange: { value: 1, title: "+1" },
            local: "06:00",
            localTime: "06:00:00",
            tzOffset: 0,
            utc: "2025-01-16T06:00:00Z",
          },
        },
      },
    }),
  ],
};

export const ALL_FLIGHTS: ISimpleFlight[] = [
  DIRECT_FLIGHT,
  DIRECT_FLIGHT_2,
  MULTI_LEG_FLIGHT,
];

// ---------------------------------------------------------------------------
// API response fixtures
// ---------------------------------------------------------------------------

export const BOARD_RESPONSE: IBoardResponse = {
  data: {
    partners: ["SU", "AF"],
    routes: ALL_FLIGHTS,
    daysOfFlight: ["2025-01-14", "2025-01-15", "2025-01-16"],
  },
};

export const EMPTY_BOARD_RESPONSE: IBoardResponse = {
  data: {
    partners: [],
    routes: [],
    daysOfFlight: [],
  },
};

export const SINGLE_FLIGHT_RESPONSE: IBoardResponse = {
  data: {
    partners: ["SU"],
    routes: [DIRECT_FLIGHT],
    daysOfFlight: ["2025-01-15"],
  },
};

export const CALENDAR_DAYS = ["2025-01-14", "2025-01-15", "2025-01-16", "2025-01-17"];
