import type { DatabaseSync } from "node:sqlite";
import type { Relationship, RelationshipLifecycleState, RelationshipObjectKind, RelationshipType } from "@oscharko-dev/keiko-contracts";
export declare const MAX_LIST_LIMIT = 256;
export declare const DEFAULT_LIST_LIMIT = 64;
export declare const MAX_IMPACT_DEPTH = 3;
export declare const DEFAULT_IMPACT_DEPTH = 1;
export declare const MAX_IMPACT_NODES = 1024;
export declare const DEFAULT_IMPACT_NODES = 256;
export declare const MAX_IMPACT_RELATIONSHIPS = 2048;
export declare const DEFAULT_IMPACT_RELATIONSHIPS = 512;
export declare const LIFECYCLE_HISTORY_RETAIN = 32;
export declare const MAX_RELATIONSHIPS_PER_QUERY = 2048;
export type RelationshipScope = {
    readonly kind: "user";
    readonly userId: string;
    readonly workspaceId: string;
} | {
    readonly kind: "workspace";
    readonly workspaceId: string;
} | {
    readonly kind: "project";
    readonly projectId: string;
    readonly workspaceId: string;
} | {
    readonly kind: "workflow";
    readonly workflowDefinitionId: string;
    readonly workspaceId: string;
} | {
    readonly kind: "global";
    readonly workspaceId: string;
};
export interface StoredRelationship extends Relationship {
    readonly confidence?: number | undefined;
    readonly summary?: string | undefined;
    readonly scope: RelationshipScope;
}
export interface NewRelationship {
    readonly id: string;
    readonly workspaceId: string;
    readonly scope: RelationshipScope;
    readonly type: RelationshipType;
    readonly source: {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
        readonly workspaceId: string;
    };
    readonly target: {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
        readonly workspaceId: string;
    };
    readonly lifecycleState: RelationshipLifecycleState;
    readonly confidence?: number | undefined;
    readonly summary?: string | undefined;
    readonly createdAt: number;
    readonly updatedAt: number;
    readonly etag: string;
}
export interface RelationshipListQuery {
    readonly workspaceId: string;
    readonly sourceKind?: RelationshipObjectKind | undefined;
    readonly sourceId?: string | undefined;
    readonly targetKind?: RelationshipObjectKind | undefined;
    readonly targetId?: string | undefined;
    readonly type?: RelationshipType | undefined;
    readonly lifecycle?: RelationshipLifecycleState | undefined;
    readonly limit: number;
    readonly afterEtag?: string | undefined;
}
export interface RelationshipListResult {
    readonly entries: readonly StoredRelationship[];
    readonly truncated: boolean;
    readonly nextCursor: string | undefined;
}
export interface RelationshipCardinalitySnapshot {
    readonly producesEvidenceForSource: number;
    readonly startsWorkflowForTarget: number;
}
export interface RelationshipLifecycleHistoryRow {
    readonly relationshipId: string;
    readonly fromState: RelationshipLifecycleState;
    readonly toState: RelationshipLifecycleState;
    readonly occurredAt: number;
    readonly summary?: string | undefined;
}
export interface RelationshipHealthEndpointRef {
    readonly kind: RelationshipObjectKind;
    readonly id: string;
}
export interface RelationshipHealthRelationshipRef {
    readonly id: string;
    readonly type: RelationshipType;
    readonly source: RelationshipHealthEndpointRef;
    readonly target: RelationshipHealthEndpointRef;
    readonly lifecycle: RelationshipLifecycleState;
}
export interface RelationshipHealthFindings {
    readonly orphanedEndpoints: readonly RelationshipHealthEndpointRef[];
    readonly orphanedEndpointsTruncated: boolean;
    readonly staleRelationships: readonly RelationshipHealthRelationshipRef[];
    readonly staleRelationshipsTruncated: boolean;
    readonly blockedRelationships: readonly RelationshipHealthRelationshipRef[];
    readonly blockedRelationshipsTruncated: boolean;
    readonly failedRelationships: readonly RelationshipHealthRelationshipRef[];
    readonly failedRelationshipsTruncated: boolean;
    readonly invalidReferences: readonly RelationshipHealthRelationshipRef[];
    readonly invalidReferencesTruncated: boolean;
    readonly cycleParticipants: readonly RelationshipHealthRelationshipRef[];
    readonly cycleScanTruncated: boolean;
}
export interface RelationshipHealthSummary {
    readonly checkedAt: number;
    readonly totals: Readonly<Record<RelationshipLifecycleState, number>>;
    readonly truncated: boolean;
    readonly findings: RelationshipHealthFindings;
}
export declare function insertRelationship(db: DatabaseSync, rel: NewRelationship): StoredRelationship;
export declare function getRelationship(db: DatabaseSync, id: string, workspaceId: string): StoredRelationship | undefined;
export declare function getRelationshipEtag(db: DatabaseSync, id: string, workspaceId: string): string | undefined;
export interface UpdateLifecycleArgs {
    readonly id: string;
    readonly workspaceId: string;
    readonly to: RelationshipLifecycleState;
    readonly previous: RelationshipLifecycleState;
    readonly newEtag: string;
    readonly updatedAt: number;
    readonly summary?: string | undefined;
}
export declare function updateRelationshipLifecycle(db: DatabaseSync, args: UpdateLifecycleArgs): StoredRelationship;
export interface ReconnectArgs {
    readonly id: string;
    readonly workspaceId: string;
    readonly target: {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
    };
    readonly newEtag: string;
    readonly updatedAt: number;
    readonly summary?: string | undefined;
}
export declare function reconnectRelationship(db: DatabaseSync, args: ReconnectArgs): StoredRelationship;
export declare function relationshipCardinalitySnapshot(db: DatabaseSync, workspaceId: string, source: {
    readonly kind: RelationshipObjectKind;
    readonly id: string;
}, target: {
    readonly kind: RelationshipObjectKind;
    readonly id: string;
}): RelationshipCardinalitySnapshot;
export declare function listRelationships(db: DatabaseSync, q: RelationshipListQuery): RelationshipListResult;
export declare function findRelationshipsBySource(db: DatabaseSync, workspaceId: string, source: {
    readonly kind: RelationshipObjectKind;
    readonly id: string;
}, limit: number): readonly StoredRelationship[];
export declare function findRelationshipsByTarget(db: DatabaseSync, workspaceId: string, target: {
    readonly kind: RelationshipObjectKind;
    readonly id: string;
}, limit: number): readonly StoredRelationship[];
export declare function listRelationshipLifecycleHistory(db: DatabaseSync, relationshipId: string, limit?: number): readonly RelationshipLifecycleHistoryRow[];
export interface DependencyWalkOptions {
    readonly workspaceId: string;
    readonly originId: string;
    readonly direction: "outgoing" | "incoming" | "both";
    readonly maxDepth: number;
    readonly maxNodes: number;
    readonly maxRelationships: number;
}
export interface DependencyWalkResult {
    readonly relationships: readonly StoredRelationship[];
    readonly nodes: readonly {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
    }[];
    readonly truncated: boolean;
    readonly truncationReason: "max-depth" | "max-nodes" | "max-relationships" | null;
    readonly depthReached: number;
}
export declare function walkDependencies(db: DatabaseSync, options: DependencyWalkOptions): DependencyWalkResult;
export interface ImpactWalkOptions {
    readonly workspaceId: string;
    readonly endpoint: {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
    };
    readonly direction: "outgoing" | "incoming" | "both";
    readonly maxDepth: number;
    readonly maxNodes: number;
    readonly maxRelationships: number;
}
export declare function computeImpact(db: DatabaseSync, options: ImpactWalkOptions): DependencyWalkResult;
export declare function graphHealth(db: DatabaseSync, workspaceId: string): RelationshipHealthSummary;
//# sourceMappingURL=relationships.d.ts.map