import type { IncomingMessage } from "node:http";
import type { RelationshipLifecycleState, RelationshipObjectKind, RelationshipType } from "@oscharko-dev/keiko-contracts";
import type { RouteContext, RouteResult } from "./routes.js";
import { STREAMING } from "./routes.js";
import type { UiHandlerDeps } from "./deps.js";
import { type DependencyWalkResult, type RelationshipHealthFindings, type RelationshipScope, type StoredRelationship } from "./store/relationships.js";
import type { RelationshipAuditEntryRow, RelationshipAuditKind } from "./store/relationship-audit.js";
export type RelationshipScopeResolver = (req: IncomingMessage) => {
    readonly workspaceId: string;
} | undefined;
export interface RelationshipStore {
    createRelationship(input: CreateRelationshipInput): {
        readonly relationship: StoredRelationship;
        readonly etag: string;
    };
    getRelationship(workspaceId: string, id: string): StoredRelationship | undefined;
    getEtag(workspaceId: string, id: string): string | undefined;
    listRelationships(query: ListQuery): ListResult;
    updateLifecycle(args: UpdateLifecycleInput): {
        readonly relationship: StoredRelationship;
        readonly etag: string;
    };
    reconnect(args: ReconnectInput): {
        readonly relationship: StoredRelationship;
        readonly etag: string;
    };
    walkDependencies(args: WalkArgs): DependencyWalkResult;
    computeImpact(args: ImpactArgs): DependencyWalkResult;
    graphHealth(workspaceId: string): GraphHealth;
    lifecycleHistory(workspaceId: string, id: string): readonly LifecycleHistoryRow[];
    recordAuditEntry(input: AuditEntryInput): RelationshipAuditEntryRow;
}
export interface CreateRelationshipInput {
    readonly workspaceId: string;
    readonly scope: RelationshipScope;
    readonly type: RelationshipType;
    readonly source: {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
    };
    readonly target: {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
    };
    readonly lifecycleState: RelationshipLifecycleState;
    readonly confidence?: number | undefined;
    readonly summary?: string | undefined;
}
export interface ListQuery {
    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;
}
export interface ListResult {
    readonly entries: readonly StoredRelationship[];
    readonly truncated: boolean;
    readonly nextCursor: string | undefined;
}
export interface UpdateLifecycleInput {
    readonly workspaceId: string;
    readonly id: string;
    readonly currentEtag: string;
    readonly to: RelationshipLifecycleState;
    readonly summary?: string | undefined;
}
export interface ReconnectInput {
    readonly workspaceId: string;
    readonly id: string;
    readonly currentEtag: string;
    readonly target: {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
    };
    readonly summary?: string | undefined;
}
export interface WalkArgs {
    readonly workspaceId: string;
    readonly originId: string;
    readonly direction: "outgoing" | "incoming" | "both";
    readonly maxDepth: number;
    readonly maxNodes: number;
    readonly maxRelationships: number;
}
export interface ImpactArgs {
    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 interface GraphHealth {
    readonly checkedAt: number;
    readonly totals: Readonly<Record<RelationshipLifecycleState, number>>;
    readonly truncated: boolean;
    readonly findings: RelationshipHealthFindings;
}
export interface LifecycleHistoryRow {
    readonly fromState: RelationshipLifecycleState;
    readonly toState: RelationshipLifecycleState;
    readonly occurredAt: number;
    readonly summary?: string | undefined;
}
export interface AuditEntryInput {
    readonly workspaceId: string;
    readonly kind: RelationshipAuditKind;
    readonly relationshipId?: string | undefined;
    readonly actor: {
        readonly surface: "system" | "inspector" | "chat";
        readonly redactedActorId: string;
    };
    readonly summary: string;
    readonly payload: Readonly<Record<string, unknown>>;
}
export interface RelationshipHandlerDeps {
    readonly scopeResolver: RelationshipScopeResolver;
    readonly store: RelationshipStore;
}
export declare function _resetIdempotencyStoreForTests(): void;
declare function hashBody(raw: string): string;
interface ProposalInput {
    readonly type: RelationshipType;
    readonly source: {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
    };
    readonly target: {
        readonly kind: RelationshipObjectKind;
        readonly id: string;
    };
    readonly scope: RelationshipScope;
    readonly summary?: string | undefined;
}
declare function parseProposal(body: Record<string, unknown>, workspaceId: string): ProposalInput;
export interface RelationshipHandlerSet {
    readonly handleValidate: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handleCreate: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handleList: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handleGet: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handlePatch: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handleDelete: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handleDependencies: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handleImpact: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handleExplain: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handleHealth: (ctx: RouteContext, deps: UiHandlerDeps) => Promise<RouteResult>;
    readonly handleEvents: (ctx: RouteContext, deps: UiHandlerDeps) => RouteResult | typeof STREAMING;
}
declare function handleValidateImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handleCreateImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handleListImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handleGetImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handlePatchImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handleDeleteImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handleDependenciesImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handleImpactImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handleExplainImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handleHealthImpl(ctx: RouteContext, deps: UiHandlerDeps): Promise<RouteResult>;
declare function handleEventsImpl(ctx: RouteContext, deps: UiHandlerDeps): RouteResult | typeof STREAMING;
export declare const handleRelationshipValidate: typeof handleValidateImpl;
export declare const handleRelationshipCreate: typeof handleCreateImpl;
export declare const handleRelationshipList: typeof handleListImpl;
export declare const handleRelationshipGet: typeof handleGetImpl;
export declare const handleRelationshipPatch: typeof handlePatchImpl;
export declare const handleRelationshipDelete: typeof handleDeleteImpl;
export declare const handleRelationshipDependencies: typeof handleDependenciesImpl;
export declare const handleRelationshipImpact: typeof handleImpactImpl;
export declare const handleRelationshipExplain: typeof handleExplainImpl;
export declare const handleRelationshipHealth: typeof handleHealthImpl;
export declare const handleRelationshipEvents: typeof handleEventsImpl;
export declare const _testing: {
    readonly parseProposal: typeof parseProposal;
    readonly hashBody: typeof hashBody;
};
import type { DatabaseSync } from "node:sqlite";
export interface CreateRelationshipStorePortOptions {
    readonly db: DatabaseSync;
    readonly redactString: (value: string) => string;
    readonly now?: (() => number) | undefined;
    readonly newId?: (() => string) | undefined;
}
export declare function createRelationshipStorePort(options: CreateRelationshipStorePortOptions): RelationshipStore;
export {};
//# sourceMappingURL=relationship-handlers.d.ts.map