import { type CommonReservedFields, type NoReservedFields, defaultGqlPermission, defaultPermission, } from "@tailor-platform/erp-kit/core"; import { db, type TailorAnyDBField, type TailorAnyDBType } from "@tailor-platform/sdk"; // Normalized event-type enum values (model doc): the physical act being punched const EVENT_TYPES = [ "CLOCK_IN", "CLOCK_OUT", "BREAK_START", "BREAK_END", "STEP_OUT", "STEP_IN", ] as const; const builtins = (params: { assignmentType?: TailorAnyDBType }) => { // Cross-module FK: relation only when the foreign type is injected; plain uuid at codegen const assignmentId = db .uuid() .description( "Foreign key to the workforce Assignment effective on occurredAt (whose punch this is)", ); return { assignmentId: params.assignmentType ? assignmentId.relation({ type: "n-1", toward: { type: params.assignmentType, as: "assignment" }, backward: "timeClockEvents", }) : assignmentId, eventType: db .enum(EVENT_TYPES) .description( "Normalized punch event type (CLOCK_IN/CLOCK_OUT/BREAK_START/BREAK_END/STEP_OUT/STEP_IN)", ), occurredAt: db .datetime() .description( "Required real-world instant of the punch; carries no computed workday - the day-breaker derives the workday downstream", ), // Immutable fact: which device/channel emitted the punch (source attribute, ADR-023). // Voids/unvoids are recorded in the separate append-only TimeClockEventVoid table, never // by mutating or appending a marker to this immutable event row. source: db .string() .description( "Punch source/device key (catalog data, not a fixed enum; e.g. WEB / MOBILE / KIOSK / IC_CARD / BIOMETRIC / SLACK / IMPORT) — the app defines the set it recognizes", ), }; }; type ReservedFields = keyof ReturnType | CommonReservedFields; export interface CreateTimeClockEventTypeParams> { fields?: NoReservedFields; assignmentType?: TailorAnyDBType; } export function createTimeClockEventType>( params: CreateTimeClockEventTypeParams, ) { return db .table("TimeClockEvent", { ...builtins(params), ...((params.fields ?? {}) as F), ...db.fields.timestamps(), }) .permission(defaultPermission) .gqlPermission(defaultGqlPermission); } // Codegen instance with no cross-module types; real FK injected via module.ts export const timeClockEvent = createTimeClockEventType({});