import type { BoardFieldOp } from "@/domain/work-orders/mappers/expand-scalar-board-ops"; import type { WorkOrderTablePatch } from "@/domain/work-orders/types/work-order-table-row"; function hasScheduleRelatedPatch(patch: WorkOrderTablePatch): boolean { return ( patch.scheduledOn !== undefined || patch.targetWeek !== undefined || patch.scheduleWeekOnly !== undefined ); } /** Schedule/week-only ops in the stable order the board API expects. */ export function expandScheduleBoardOps(patch: WorkOrderTablePatch): BoardFieldOp[] { if (!hasScheduleRelatedPatch(patch)) { return []; } const ops: BoardFieldOp[] = []; if (patch.scheduleWeekOnly === true) { ops.push({ field: "scheduleWeekOnly", value: "true" }); if (patch.targetWeek !== undefined) { ops.push({ field: "targetWeek", value: patch.targetWeek }); } if (patch.scheduledOn !== undefined) { ops.push({ field: "scheduledDate", value: patch.scheduledOn }); } return ops; } if (patch.scheduleWeekOnly === false) { ops.push({ field: "scheduleWeekOnly", value: "false" }); } if (patch.scheduledOn !== undefined) { ops.push({ field: "scheduledDate", value: patch.scheduledOn }); } if (patch.targetWeek !== undefined) { ops.push({ field: "targetWeek", value: patch.targetWeek }); } return ops; }