import { ok, type ReadonlyDB } from "@tailor-platform/erp-kit/core"; import type { DB } from "../generated/kysely-tailordb"; export interface GetWorkRegimeByKeyInput { companyId: string; key: string; } /** * Function: getWorkRegimeByKey * Description: Resolves a company's WorkRegime by its stable (companyId, key) * business key. Returns null (not an error) when no entry matches — the key * lookup callers use when validating a WorkerEmployment's work regime. */ export async function run(db: ReadonlyDB, input: GetWorkRegimeByKeyInput) { const workRegime = await db .selectFrom("WorkRegime") .selectAll() .where("companyId", "=", input.companyId) .where("key", "=", input.key) .executeTakeFirst(); return ok({ workRegime: workRegime ?? null }); }