import { describe, expect, it } from "vitest";
import {
  buildHolidayCalendarCreateData,
  buildHolidayCalendarEntryCreateData,
  buildHolidayCalendarEntryUpdateData,
  buildHolidayCalendarUpdateData,
  holidayCalendarDetailInclude,
  holidayCalendarEntryOrderBy,
  holidayCalendarListInclude,
} from "../router/holiday-calendar-support.js";

describe("holiday calendar support", () => {
  it("exposes shared include definitions", () => {
    expect(holidayCalendarEntryOrderBy).toEqual([
      { date: "asc" },
      { name: "asc" },
    ]);

    expect(holidayCalendarDetailInclude).toEqual({
      country: { select: { id: true, code: true, name: true } },
      metroCity: { select: { id: true, name: true } },
      entries: { orderBy: holidayCalendarEntryOrderBy },
    });

    expect(holidayCalendarListInclude).toEqual({
      country: { select: { id: true, code: true, name: true } },
      metroCity: { select: { id: true, name: true } },
      entries: { orderBy: holidayCalendarEntryOrderBy },
      _count: { select: { entries: true } },
    });
  });

  it("builds calendar create and sparse update payloads", () => {
    expect(buildHolidayCalendarCreateData({
      name: "Bayern Feiertage",
      scopeType: "STATE",
      countryId: "country_de",
      stateCode: "by",
      isActive: undefined,
      priority: undefined,
      normalizedScope: {
        stateCode: "BY",
        metroCityId: null,
      },
    })).toEqual({
      name: "Bayern Feiertage",
      scopeType: "STATE",
      countryId: "country_de",
      stateCode: "BY",
      isActive: true,
      priority: 0,
    });

    expect(buildHolidayCalendarUpdateData({
      data: {
        name: "Augsburg lokal",
        metroCityId: null,
        priority: 7,
      },
      resolvedScope: {
        stateCode: null,
        metroCityId: null,
      },
    })).toEqual({
      name: "Augsburg lokal",
      metroCityId: null,
      priority: 7,
    });
  });

  it("builds holiday entry create and sparse update payloads", () => {
    const normalizedDate = new Date("2026-01-06T00:00:00.000Z");

    expect(buildHolidayCalendarEntryCreateData({
      data: {
        holidayCalendarId: "cal_by",
        date: new Date("2026-01-06T13:15:00.000Z"),
        name: "Heilige Drei Koenige",
        isRecurringAnnual: undefined,
        source: "state",
      },
      date: normalizedDate,
    })).toEqual({
      holidayCalendarId: "cal_by",
      date: normalizedDate,
      name: "Heilige Drei Koenige",
      isRecurringAnnual: false,
      source: "state",
    });

    expect(buildHolidayCalendarEntryUpdateData({
      data: {
        date: normalizedDate,
        source: null,
      },
      date: normalizedDate,
    })).toEqual({
      date: normalizedDate,
      source: null,
    });
  });
});
