import type { ServiceCtx } from "@/server/services/context"; import { transitionWorkOrder, type TransitionResult } from "@/server/services/work-orders/transition"; /** * Billing workflow (US-009). All paths go through transitionWorkOrder, which enforces * `work_order:release_billing` and — for the release — an approved completion report. * The event `work_order.released_for_billing` is emitted by the transition. */ export async function releaseForBilling( ctx: ServiceCtx, input: { workOrderId: string; baseVersion?: number }, ): Promise { return transitionWorkOrder(ctx, { workOrderId: input.workOrderId, to: "released_for_billing", baseVersion: input.baseVersion }); } /** Reject: back to the team for correction (in_review → in_progress), reason mandatory. */ export async function rejectForCorrection( ctx: ServiceCtx, input: { workOrderId: string; reason: string; baseVersion?: number }, ): Promise { return transitionWorkOrder(ctx, { workOrderId: input.workOrderId, to: "in_progress", reason: input.reason, baseVersion: input.baseVersion }); } /** Revoke a billing release (released_for_billing → in_review), reason mandatory. */ export async function revokeBillingRelease( ctx: ServiceCtx, input: { workOrderId: string; reason: string; baseVersion?: number }, ): Promise { return transitionWorkOrder(ctx, { workOrderId: input.workOrderId, to: "in_review", reason: input.reason, baseVersion: input.baseVersion }); } export async function markBilled(ctx: ServiceCtx, input: { workOrderId: string; baseVersion?: number }): Promise { return transitionWorkOrder(ctx, { workOrderId: input.workOrderId, to: "billed", baseVersion: input.baseVersion }); }