import { getCodeWorkflow } from "../../lib/code-registry.js";
function resolveSource(definition) {
  if (definition.codeWorkflowId) return "code_override";
  return "user";
}
function serializeWorkflowDefinition(definition) {
  const source = resolveSource(definition);
  const codeModuleId = source === "code_override" && definition.codeWorkflowId ? getCodeWorkflow(definition.codeWorkflowId)?.moduleId ?? null : null;
  return {
    id: definition.id,
    workflowId: definition.workflowId,
    workflowName: definition.workflowName,
    description: definition.description ?? null,
    version: definition.version,
    definition: definition.definition,
    metadata: definition.metadata ?? null,
    enabled: definition.enabled,
    effectiveFrom: definition.effectiveFrom ?? null,
    effectiveTo: definition.effectiveTo ?? null,
    tenantId: definition.tenantId,
    organizationId: definition.organizationId,
    createdBy: definition.createdBy ?? null,
    updatedBy: definition.updatedBy ?? null,
    createdAt: definition.createdAt,
    updatedAt: definition.updatedAt,
    deletedAt: definition.deletedAt ?? null,
    source,
    isCodeBased: source === "code" || source === "code_override",
    codeModuleId
  };
}
function serializeCodeWorkflowDefinition(codeDef, syntheticId) {
  return {
    id: syntheticId,
    workflowId: codeDef.workflowId,
    workflowName: codeDef.workflowName,
    description: codeDef.description ?? null,
    version: codeDef.version,
    definition: codeDef.definition,
    metadata: codeDef.metadata ?? null,
    enabled: codeDef.enabled,
    effectiveFrom: null,
    effectiveTo: null,
    tenantId: null,
    organizationId: null,
    createdBy: null,
    updatedBy: null,
    createdAt: null,
    updatedAt: null,
    deletedAt: null,
    source: "code",
    isCodeBased: true,
    codeModuleId: codeDef.moduleId
  };
}
export {
  serializeCodeWorkflowDefinition,
  serializeWorkflowDefinition
};
//# sourceMappingURL=serialize.js.map
