import { type CommonReservedFields, type NoReservedFields, defaultGqlPermission, defaultPermission, } from "@tailor-platform/erp-kit/core"; import { db, type TailorAnyDBField, type TailorAnyDBType } from "@tailor-platform/sdk"; // Plain ACTIVE/INACTIVE status; deactivate/reactivate flip it. INACTIVE regimes stay referenced by // historical WorkerEmployment rows but are not selectable for new employments. export const WORK_REGIME_STATUSES = ["ACTIVE", "INACTIVE"] as const; const builtins = (params: { companyType?: TailorAnyDBType }) => { // Cross-module FK: relation only when the organization Company type is injected; plain uuid at codegen. const companyId = db .uuid() .description( "Foreign key to the organization Company this work-regime catalog entry belongs to", ); return { companyId: params.companyType ? companyId.relation({ type: "n-1", toward: { type: params.companyType, as: "company" }, backward: "workRegimes", }) : companyId, // Stable, machine-facing key unique within the company; referenced by id, this is the handle // (e.g. STANDARD, FLEX, DISCRETIONARY). The set is data, not a fixed enum — each company defines // the work/time regimes its calculation strategy and work rules key off. key: db.string().description("Stable work-regime key, unique within the company"), displayName: db.string().description("Human-facing label for the work regime"), status: db.enum(WORK_REGIME_STATUSES).description("ACTIVE or INACTIVE"), }; }; type ReservedFields = keyof ReturnType | CommonReservedFields; export interface CreateWorkRegimeTypeParams> { fields?: NoReservedFields; companyType?: TailorAnyDBType; } export function createWorkRegimeType>( params: CreateWorkRegimeTypeParams, ) { return db .table("WorkRegime", { ...builtins(params), ...((params.fields ?? {}) as F), ...db.fields.timestamps(), }) .indexes({ fields: ["companyId", "key"], unique: true, name: "work_regime_company_key_unique_idx", }) .permission(defaultPermission) .gqlPermission(defaultGqlPermission); } // Codegen instance with no cross-module types; real FK injected via module.ts export const workRegime = createWorkRegimeType({});