import { type WorkflowStepDto, type WorkflowTriggerBindingDto } from '@/services/api/communicationsApi';
import type { WorkflowMetadata } from '@/components/platform/administration/workflows/builder/WorkflowInspectorPanel';
import { type WorkflowSnapshot } from './useWorkflowDirty';
/**
 * Codes returned by validateForSave so the page can show a structured message
 * (with the offending field) instead of an opaque string. Each maps to a
 * translation key under `workflows.builder.validation.*`.
 */
export type ValidationFailureCode = 'codeRequired' | 'codeFormat' | 'codeReserved' | 'nameRequired' | 'stepNameRequired' | 'stepNameDuplicate' | 'conditionExpression' | 'stepInputJson' | 'danglingPointer';
export interface ValidationFailure {
    readonly code: ValidationFailureCode;
    readonly params?: Record<string, string>;
}
export interface UseWorkflowSaveInput {
    readonly workflowId: string | undefined;
    readonly metadata: WorkflowMetadata;
    readonly bindings: readonly WorkflowTriggerBindingDto[];
    readonly steps: readonly WorkflowStepDto[];
    readonly initialSnapshot: WorkflowSnapshot | null;
}
export interface UseWorkflowSaveResult {
    readonly saving: boolean;
    readonly testing: boolean;
    readonly save: () => Promise<SaveOutcome>;
    readonly test: (variables: Record<string, unknown> | undefined) => Promise<TestOutcome>;
    readonly validate: () => ValidationFailure | null;
}
export interface SaveOutcome {
    readonly success: boolean;
    readonly newWorkflowId?: string;
    readonly errorMessage?: string;
    readonly errorCode?: 'validation' | 'unauthorized' | 'forbidden' | 'conflict' | 'server' | 'network' | 'partial';
    readonly partial?: boolean;
    readonly validationFailure?: ValidationFailure;
}
export interface TestOutcome {
    readonly success: boolean;
    readonly errorMessage?: string;
}
/**
 * Owns the entire save lifecycle: validation → cascade POST/PUT/DELETE → reorder.
 *
 * Production guarantees:
 *
 * - **Validation runs first** — no API roundtrip happens when local state is
 *   invalid. The caller receives a structured failure code with the field name
 *   so the toast renders a clear French/English/etc. message.
 *
 * - **Errors are granular** — 4xx and 5xx are mapped to distinct outcome codes
 *   so the page can react appropriately (e.g. force re-login on 401, surface
 *   the conflicting code on 409, keep state on 5xx so the user can retry
 *   without losing edits).
 *
 * - **Best-effort atomicity** — the cascade order is workflow → deletes →
 *   creates → updates → reorder. If a mid-cascade call fails we abort, reload
 *   the workflow from the server to pick up any partially-persisted changes,
 *   and return `partial: true` so the page can flag a manual cleanup.
 *
 * - **Concurrency safe** — `saving` becomes true synchronously so a double-
 *   click on Save dispatches at most one cascade per user gesture.
 */
export declare function useWorkflowSave(input: UseWorkflowSaveInput): UseWorkflowSaveResult;
//# sourceMappingURL=useWorkflowSave.d.ts.map