import { err, ok, type ReadonlyDB } from "@tailor-platform/erp-kit/core"; import type { DB } from "../generated/kysely-tailordb"; import { WorkRuleNotFoundError } from "../lib/errors.generated"; export interface GetWorkRuleInput { id: string; } /** * Function: getWorkRule * Description: Retrieves a single WorkRule generation by its surrogate id, * returning the rounding configuration, break deduction, daily overtime * threshold, night-work window, and premium-category pins, along with * effective-dating fields. */ export async function run(db: ReadonlyDB, input: GetWorkRuleInput) { const workRule = await db .selectFrom("WorkRule") .selectAll() .where("id", "=", input.id) .executeTakeFirst(); if (!workRule) { return err(new WorkRuleNotFoundError(input.id)); } return ok({ workRule }); }