import { controllerProcedure, protectedProcedure } from "../trpc.js";
import {
  TimelineDetailFiltersSchema,
  TimelineWindowFiltersSchema,
} from "./timeline-read-schema-support.js";
import {
  loadTimelineHolidayOverlays,
} from "./timeline-holiday-load-support.js";
import {
  readMyTimelineHolidayOverlays,
  readTimelineHolidayOverlayDetail,
} from "./timeline-holiday-procedure-support.js";
import {
  formatTimelineHolidayOverlays,
  summarizeTimelineHolidayOverlays,
  type TimelineHolidayOverlayRecord,
} from "./timeline-holiday-support.js";

export {
  loadTimelineHolidayOverlays,
  loadTimelineHolidayOverlaysForReadModel,
} from "./timeline-holiday-load-support.js";

export function formatHolidayOverlays(
  overlays: TimelineHolidayOverlayRecord[],
) {
  return formatTimelineHolidayOverlays(overlays);
}

export function summarizeHolidayOverlays(
  overlays: ReturnType<typeof formatHolidayOverlays>,
) {
  return summarizeTimelineHolidayOverlays(overlays);
}

export const timelineHolidayReadProcedures = {
  getHolidayOverlays: controllerProcedure
    .input(TimelineWindowFiltersSchema)
    .query(async ({ ctx, input }) => loadTimelineHolidayOverlays(ctx.db, input)),

  getMyHolidayOverlays: protectedProcedure
    .input(TimelineWindowFiltersSchema)
    .query(async ({ ctx, input }) => readMyTimelineHolidayOverlays(ctx, input)),

  getHolidayOverlayDetail: controllerProcedure
    .input(TimelineDetailFiltersSchema)
    .query(async ({ ctx, input }) => readTimelineHolidayOverlayDetail(ctx.db, input)),
};
