import { type CommonReservedFields, type NoReservedFields, defaultGqlPermission, defaultPermission, } from "@tailor-platform/erp-kit/core"; import { db, type TailorAnyDBField } from "@tailor-platform/sdk"; import { holidayCalendar } from "./holidayCalendar"; const HOLIDAY_KINDS = ["STATUTORY", "PRESCRIBED"] as const; const builtins = { // Intra-module FK: the HolidayCalendar this holiday belongs to. holidayDate is unique // per calendar (DUPLICATE_HOLIDAY_DATE, enforced at the command layer), so the same date // can be a holiday in one calendar and a working day in another. calendarId: db .uuid() .relation({ type: "n-1", toward: { type: holidayCalendar, as: "calendar" }, backward: "holidays", }) .description("Foreign key to the HolidayCalendar this holiday belongs to"), holidayDate: db.date().description("The calendar date registered as a holiday"), // STATUTORY (statutory holiday) or PRESCRIBED (company holiday) — bound to premium/classification, never to name (ADR-015) holidayKind: db .enum(HOLIDAY_KINDS) .description("Normalized holiday kind: STATUTORY or PRESCRIBED"), name: db.string().description("Display name of the holiday"), }; type ReservedFields = keyof typeof builtins | CommonReservedFields; export interface CreateCompanyHolidayTypeParams> { fields?: NoReservedFields; } export function createCompanyHolidayType>( params: CreateCompanyHolidayTypeParams, ) { return db .table("CompanyHoliday", { ...builtins, ...((params.fields ?? {}) as F), ...db.fields.timestamps(), }) .permission(defaultPermission) .gqlPermission(defaultGqlPermission); } export const companyHoliday = createCompanyHolidayType({});