import { describe, expect, it } from "vitest";
import {
  celsiusToDisplay,
  formatMoney,
  fromMinor,
  localeDefaultsForRegion,
  money,
  toMinor,
} from "../src/index.js";

describe("locale-preferenser (i18n-spec §6)", () => {
  it("regiondefaults: USA får US_CUSTOMARY + Fahrenheit + USD + söndagsstart", () => {
    const us = localeDefaultsForRegion("us");
    expect(us.measurementSystem).toBe("US_CUSTOMARY");
    expect(us.temperatureUnit).toBe("FAHRENHEIT");
    expect(us.currencyCode).toBe("USD");
    expect(us.firstDayOfWeek).toBe(0);
    expect(us.use24HourTime).toBe(false);
  });
  it("okänd region faller tillbaka till metriska defaults", () => {
    const xx = localeDefaultsForRegion("XX");
    expect(xx.measurementSystem).toBe("METRIC");
    expect(xx.regionCode).toBe("XX");
  });
  it("temperatur: canonical Celsius → Fahrenheit-visning", () => {
    expect(celsiusToDisplay(200, "FAHRENHEIT")).toBe(392);
    expect(celsiusToDisplay(200, "CELSIUS")).toBe(200);
  });
});

describe("pengar i minor units (i18n-spec §20)", () => {
  it("SEK: 79 kr = 7900 öre, tillbaka utan förlust", () => {
    expect(toMinor(79, "SEK")).toBe(7900);
    expect(fromMinor(money(7900, "SEK"))).toBe(79);
  });
  it("valutor utan decimaler (ISK) hanteras", () => {
    expect(toMinor(500, "ISK")).toBe(500);
    expect(fromMinor(money(500, "ISK"))).toBe(500);
  });
  it("amountMinor måste vara heltal – aldrig floating point", () => {
    expect(() => money(79.5, "SEK")).toThrow();
  });
  it("formattering är locale-medveten", () => {
    const sv = formatMoney(money(7900, "SEK"), "sv-SE");
    const us = formatMoney(money(7900, "USD"), "en-US");
    expect(sv).toContain("79");
    expect(us).toContain("79");
  });
});
