import { FlowExecCtx } from "@/core/flow.execution.context"; import { ERROR_CODES, type Err } from "@pkg/result"; import { getError } from "@pkg/logger"; export const deviceErrors = { dbError: (fctx: FlowExecCtx, detail: string): Err => getError({ flowId: fctx.flowId, code: ERROR_CODES.DATABASE_ERROR, message: "Database operation failed", description: "Please try again later", detail, }), deviceNotFound: (fctx: FlowExecCtx, id: number): Err => getError({ flowId: fctx.flowId, code: ERROR_CODES.NOT_FOUND, message: "Device not found", description: "The requested device does not exist", detail: `No device found with ID: ${id}`, }), listFailed: (fctx: FlowExecCtx, detail: string): Err => getError({ flowId: fctx.flowId, code: ERROR_CODES.DATABASE_ERROR, message: "Failed to list devices", description: "Try again later", detail, }), createFailed: (fctx: FlowExecCtx, detail: string): Err => getError({ flowId: fctx.flowId, code: ERROR_CODES.DATABASE_ERROR, message: "Failed to create device", description: "Try again later", detail, }), updateFailed: (fctx: FlowExecCtx, detail: string): Err => getError({ flowId: fctx.flowId, code: ERROR_CODES.DATABASE_ERROR, message: "Failed to update device", description: "Try again later", detail, }), deleteFailed: (fctx: FlowExecCtx, detail: string): Err => getError({ flowId: fctx.flowId, code: ERROR_CODES.DATABASE_ERROR, message: "Failed to delete device", description: "Try again later", detail, }), deviceNotAvailable: (fctx: FlowExecCtx, id: number): Err => getError({ flowId: fctx.flowId, code: ERROR_CODES.NOT_ALLOWED, message: "Device is not available", description: "The device is currently busy or offline", detail: `Device ${id} cannot be allocated in its current state`, actionable: true, }), };