/**
 * Online Board SEO parity tests.
 *
 * Registers all 6 Online Board SEO builder functions against the generic
 * SEO parity harness. Tests shape/completeness for ru and en locales.
 *
 * @module
 */

import {
  buildOnlineBoardStartSeo,
  buildFlightSearchSeo,
  buildDepartureSearchSeo,
  buildArrivalSearchSeo,
  buildRouteSearchSeo,
  buildFlightDetailsSeo,
} from "@/features/online-board/seo.js";
import type { ISimpleFlight } from "@/features/online-board/types.js";
import type { Language } from "@/i18n/resolver.js";
import { defineSeoParityTests } from "./harness.js";

// ---------------------------------------------------------------------------
// Stub translation function
// ---------------------------------------------------------------------------

function stubT(key: string, opts?: Record<string, unknown>): string {
  if (opts && Object.keys(opts).length > 0) {
    const vars = Object.entries(opts)
      .map(([k, v]) => `${k}=${String(v)}`)
      .join(",");
    return `${key}|${vars}`;
  }
  return key;
}

const CANONICAL_ORIGIN = "https://www.aeroflot.ru";

// ---------------------------------------------------------------------------
// Test flight fixture for details page
// ---------------------------------------------------------------------------

const testFlight: ISimpleFlight = {
  id: "SU100-20250115",
  routeType: "Direct",
  flightId: {
    carrier: "SU",
    flightNumber: "0100",
    suffix: "",
    date: "20250115",
  },
  flyingTime: "10h 30m",
  operatingBy: {},
  status: "Scheduled",
  leg: {
    index: 0,
    status: "Scheduled",
    flyingTime: "10h 30m",
    updated: "2025-01-15T10:00:00Z",
    dayChange: 0,
    equipment: { name: "Boeing 777-300ER", code: "773" },
    flags: { checkinAvailable: false, returnToAirport: false, routeChanged: false },
    operatingBy: {},
    departure: {
      scheduled: {
        airport: "Sheremetyevo International Airport",
        airportCode: "SVO",
        city: "Moscow",
        cityCode: "MOW",
        countryCode: "RU",
      },
      checkingStatus: "closed",
      times: {
        scheduledDeparture: {
          dayChange: { value: 0, title: "" },
          local: "2025-01-15T10:00:00",
          localTime: "10:00",
          tzOffset: 3,
          utc: "2025-01-15T07:00:00Z",
        },
      },
    },
    arrival: {
      scheduled: {
        airport: "John F. Kennedy International Airport",
        airportCode: "JFK",
        city: "New York",
        cityCode: "NYC",
        countryCode: "US",
      },
      times: {
        scheduledArrival: {
          dayChange: { value: 0, title: "" },
          local: "2025-01-15T14:30:00",
          localTime: "14:30",
          tzOffset: -5,
          utc: "2025-01-15T19:30:00Z",
        },
      },
    },
  },
};

// ---------------------------------------------------------------------------
// Register against harness
// ---------------------------------------------------------------------------

defineSeoParityTests({
  slug: "OnlineBoard",
  entries: [
    {
      label: "start page",
      render: (lang: Language) =>
        buildOnlineBoardStartSeo(stubT, lang, CANONICAL_ORIGIN),
    },
    {
      label: "flight search",
      render: (lang: Language) =>
        buildFlightSearchSeo(
          stubT,
          { type: "flight", carrier: "SU", flightNumber: "0100", date: "20250115" },
          lang,
          CANONICAL_ORIGIN,
        ),
    },
    {
      label: "departure search",
      render: (lang: Language) =>
        buildDepartureSearchSeo(
          stubT,
          { type: "departure", station: "SVO", date: "20250115" },
          lang,
          CANONICAL_ORIGIN,
          { departure: "Moscow" },
        ),
    },
    {
      label: "arrival search",
      render: (lang: Language) =>
        buildArrivalSearchSeo(
          stubT,
          { type: "arrival", station: "JFK", date: "20250115" },
          lang,
          CANONICAL_ORIGIN,
          { arrival: "New York" },
        ),
    },
    {
      label: "route search",
      render: (lang: Language) =>
        buildRouteSearchSeo(
          stubT,
          { type: "route", departure: "SVO", arrival: "JFK", date: "20250115" },
          lang,
          CANONICAL_ORIGIN,
          { departure: "Moscow", arrival: "New York" },
        ),
    },
    {
      label: "flight details",
      render: (lang: Language) =>
        buildFlightDetailsSeo(stubT, testFlight, lang, CANONICAL_ORIGIN),
    },
  ],
});
