import { AgentsManageDatabaseClient } from "../db/manage/manage-client.js";

//#region src/dolt/schema-sync.d.ts

/**
 * The branch that serves as the source of truth for schema.
 * All other branches sync their schema from this branch.
 */
declare const SCHEMA_SOURCE_BRANCH = "main";
/**
 * Represents a single schema difference between two branches.
 * Each row represents a table that differs between the branches,
 * showing the full CREATE TABLE statements for comparison.
 */
type SchemaDiff = {
  /** Table name in the source branch (e.g., "public.agent") */
  fromTableName: string;
  /** Table name in the target branch (e.g., "public.agent") */
  toTableName: string;
  /** Full CREATE TABLE statement from the source branch */
  fromCreateStatement: string;
  /** Full CREATE TABLE statement from the target branch */
  toCreateStatement: string;
};
/**
 * Result of a schema sync operation
 */
type SchemaSyncResult = {
  /** Whether a sync was performed */
  synced: boolean;
  /** Whether there were schema differences detected */
  hadDifferences: boolean;
  /** The schema differences that were found */
  differences?: SchemaDiff[];
  /** Error message if sync failed */
  error?: string;
  /** The merge commit hash if sync was successful */
  mergeCommitHash?: string;
  /** Whether sync was skipped because another request holds the lock */
  skippedDueToLock?: boolean;
};
/**
 * Options for schema sync operations
 */
type SchemaSyncOptions = {
  /** Automatically commit pending changes before syncing */
  autoCommitPending?: boolean;
  /** Custom commit message for the schema sync */
  commitMessage?: string;
  /** Author information for the commit */
  author?: {
    name: string;
    email: string;
  };
};
/**
 * Options for ensuring schema compatibility
 */
type EnsureSchemaSyncOptions = SchemaSyncOptions & {
  /** Automatically sync schema if differences are found */
  autoSync?: boolean;
};
/**
 * Get the currently active branch
 */
declare const getActiveBranch: (db: AgentsManageDatabaseClient) => () => Promise<string>;
/**
 * Get schema differences between the schema source branch and a target branch.
 * Returns an empty array if schemas are identical.
 *
 * The comparison is done as dolt_schema_diff(targetBranch, SCHEMA_SOURCE_BRANCH),
 * so fromCreateStatement shows the target branch's schema and toCreateStatement
 * shows main's schema (what we want to sync to).
 *
 * @param targetBranch - The branch to compare against the schema source
 * @returns Array of schema differences (one per table that differs)
 */
declare const getSchemaDiff: (db: AgentsManageDatabaseClient) => (targetBranch: string) => Promise<SchemaDiff[]>;
/**
 * Check if a branch has schema differences from the schema source branch
 */
declare const hasSchemaDifferences: (db: AgentsManageDatabaseClient) => (targetBranch: string) => Promise<boolean>;
/**
 * Check if the current branch has uncommitted changes
 */
declare const hasUncommittedChanges: (db: AgentsManageDatabaseClient) => () => Promise<boolean>;
/**
 * Sync schema from the schema source branch (main) into the current branch.
 * This performs a merge of the schema source branch into the current branch.
 *
 * Uses a non-blocking advisory lock to prevent duplicate syncs when multiple
 * concurrent requests attempt to sync the same branch. If another request is
 * already syncing, this function returns immediately with skippedDueToLock: true.
 *
 * Prerequisites:
 * - Current branch must not have uncommitted changes (unless autoCommitPending is true)
 * - Current branch must not be the schema source branch itself
 *
 * @param options - Sync options
 * @returns Result of the sync operation
 */
declare const syncSchemaFromMain: (db: AgentsManageDatabaseClient) => (options?: SchemaSyncOptions) => Promise<SchemaSyncResult>;
/**
 * Ensure the current branch has schema in sync with the schema source branch.
 * This is a convenience function for checking and optionally syncing schema.
 *
 * Use cases:
 * - Call before write operations to ensure schema compatibility
 * - Call before merge operations to prevent schema conflicts
 * - Call on branch checkout to keep branches up-to-date
 *
 * @param options - Options for the check and optional sync
 * @returns Result indicating current sync status
 */
declare const ensureSchemaSync: (db: AgentsManageDatabaseClient) => (options?: EnsureSchemaSyncOptions) => Promise<SchemaSyncResult>;
/**
 * Get a human-readable summary of schema differences
 */
declare const formatSchemaDiffSummary: (differences: SchemaDiff[]) => string;
/**
 * Check if two branches have compatible schemas (both are in sync with main).
 * Useful before merging two feature branches.
 *
 * @param branchA - First branch to check
 * @param branchB - Second branch to check
 * @returns Object indicating if both branches are schema-compatible
 */
declare const areBranchesSchemaCompatible: (db: AgentsManageDatabaseClient) => (branchA: string, branchB: string) => Promise<{
  compatible: boolean;
  branchADifferences: SchemaDiff[];
  branchBDifferences: SchemaDiff[];
}>;
declare const isLocalhostUrl: (url: string | undefined) => boolean;
//#endregion
export { EnsureSchemaSyncOptions, SCHEMA_SOURCE_BRANCH, SchemaDiff, SchemaSyncOptions, SchemaSyncResult, areBranchesSchemaCompatible, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getSchemaDiff, hasSchemaDifferences, hasUncommittedChanges, isLocalhostUrl, syncSchemaFromMain };