import { describe, it, expect } from "vitest";
import { shouldShowPobedaAuroraBanner } from "./PobedaAuroraBanner.js";
import type { ISimpleFlight } from "../types.js";

/**
 * Helper to build a minimal ISimpleFlight for banner detection tests.
 * Only operatingBy + flightId.carrier matter for `shouldShow`.
 */
function flight(carrier: string, flightNumber = "1234", suFallback = false): ISimpleFlight {
  // When suFallback is true, operatingBy is empty so the detector falls
  // through to resolveCarrierByFlightNumber on SU + numeric range.
  return {
    routeType: "Direct",
    flightId: { carrier: suFallback ? "SU" : carrier, flightNumber, date: "20260422", suffix: "" },
    operatingBy: suFallback ? {} : { scheduled: carrier },
    id: `${carrier}${flightNumber}`,
    leg: {
      departure: {} as never,
      arrival: {} as never,
      transition: {} as never,
      flags: {} as never,
      equipment: {} as never,
    } as never,
  } as unknown as ISimpleFlight;
}

describe("shouldShowPobedaAuroraBanner §4.1.10.1", () => {
  it("returns show=false for empty results", () => {
    expect(shouldShowPobedaAuroraBanner([])).toEqual({
      show: false,
      hasPobeda: false,
      hasAurora: false,
    });
  });

  it("returns show=true when all flights are Pobeda (DP)", () => {
    const r = shouldShowPobedaAuroraBanner([flight("DP"), flight("DP")]);
    expect(r).toEqual({ show: true, hasPobeda: true, hasAurora: false });
  });

  it("returns show=true when all flights are Aurora (HZ)", () => {
    const r = shouldShowPobedaAuroraBanner([flight("HZ")]);
    expect(r).toEqual({ show: true, hasPobeda: false, hasAurora: true });
  });

  it("returns show=true with both Pobeda and Aurora", () => {
    const r = shouldShowPobedaAuroraBanner([flight("DP"), flight("HZ")]);
    expect(r).toEqual({ show: true, hasPobeda: true, hasAurora: true });
  });

  it("returns show=false when any flight is another carrier (e.g. SU)", () => {
    const r = shouldShowPobedaAuroraBanner([flight("DP"), flight("SU")]);
    expect(r.show).toBe(false);
  });

  it("uses flight-number range when operatingBy is empty (SU5000-5399 → DP)", () => {
    const r = shouldShowPobedaAuroraBanner([flight("DP", "5200", true)]);
    expect(r).toEqual({ show: true, hasPobeda: true, hasAurora: false });
  });

  it("uses flight-number range when operatingBy is empty (SU5400-5799 → HZ)", () => {
    const r = shouldShowPobedaAuroraBanner([flight("HZ", "5500", true)]);
    expect(r).toEqual({ show: true, hasPobeda: false, hasAurora: true });
  });
});
