import { describe, expect, it } from "vitest";
import { buildFlightsMapSeo } from "./seo.js";
import { buildFlightsMapJsonLd } from "./json-ld.js";

/** Stub t() that returns the key for assertion. */
function stubT(key: string): string {
  return key;
}

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

// ---------------------------------------------------------------------------
// buildFlightsMapSeo
// ---------------------------------------------------------------------------

describe("buildFlightsMapSeo", () => {
  it("uses FLIGHTS_MAP translation keys", () => {
    const result = buildFlightsMapSeo(stubT, "ru", CANONICAL);

    expect(result.title).toBe("SEO.FLIGHTS_MAP.TITLE");
    expect(result.description).toBe("SEO.FLIGHTS_MAP.DESCRIPTION");
  });

  it("sets canonical to /{locale}/flights-map", () => {
    const result = buildFlightsMapSeo(stubT, "en", CANONICAL);

    expect(result.canonical).toBe("https://www.aeroflot.ru/en/flights-map");
  });

  it("includes hreflang with 10 entries", () => {
    const result = buildFlightsMapSeo(stubT, "ru", CANONICAL);

    expect(result.hreflang).toHaveLength(10);
  });

  it("sets og tags", () => {
    const result = buildFlightsMapSeo(stubT, "ru", CANONICAL);

    expect(result.og.title).toBe(result.title);
    expect(result.og.type).toBe("website");
    expect(result.og.locale).toBe("ru");
    expect(result.og.siteName).toBe("Aeroflot");
    expect(result.og.url).toBe("https://www.aeroflot.ru/ru/flights-map");
  });

  it("sets twitter card to summary", () => {
    const result = buildFlightsMapSeo(stubT, "ru", CANONICAL);

    expect(result.twitter).toBeDefined();
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- test assertion guards above
    expect(result.twitter!.card).toBe("summary");
  });
});

// ---------------------------------------------------------------------------
// buildFlightsMapJsonLd
// ---------------------------------------------------------------------------

describe("buildFlightsMapJsonLd", () => {
  it("returns a WebPage schema", () => {
    const result = buildFlightsMapJsonLd("ru", CANONICAL);

    expect(result["@type"]).toBe("WebPage");
  });

  it("sets the correct URL with locale", () => {
    const result = buildFlightsMapJsonLd("en", CANONICAL);

    expect(result.url).toBe("https://www.aeroflot.ru/en/flights-map");
  });

  it("sets inLanguage to the locale", () => {
    const result = buildFlightsMapJsonLd("ja", CANONICAL);

    expect(result.inLanguage).toBe("ja");
  });

  it("includes isPartOf WebSite reference", () => {
    const result = buildFlightsMapJsonLd("ru", CANONICAL);

    expect(result.isPartOf).toBeDefined();
    const site = result.isPartOf as { "@type": string; name: string; url: string };
    expect(site["@type"]).toBe("WebSite");
    expect(site.name).toBe("Aeroflot");
    expect(site.url).toBe(CANONICAL);
  });

  it("sets name with site name prefix", () => {
    const result = buildFlightsMapJsonLd("ru", CANONICAL);

    expect(result.name).toContain("Aeroflot");
    expect(result.name).toContain("Flight Map");
  });
});
