/**
 * Multi-Source Provider Configuration
 *
 * Allows a workspace to have multiple external ticket providers configured
 * simultaneously (e.g. Linear for engineering, Asana for product, Shortcut
 * for design). Each source entry includes a provider type, API key reference,
 * team/project ID, and an identifier prefix used for routing ticket keys to
 * the correct provider.
 *
 * Stored as a JSON array in workspace_settings under the key
 * `work.provider_sources`.
 */
import Database from 'better-sqlite3';
import type { WorkSourceProvider } from './config.js';
/**
 * A single provider source entry in the multi-source configuration.
 *
 * Example: { id: 'eng-linear', provider: 'linear', apiKeyRef: 'linear.api_key',
 *            teamProjectId: 'ENG', prefix: 'ENG-', label: 'Engineering' }
 */
export interface ProviderSourceEntry {
    /** Unique identifier for this source config (user-chosen, slug-like) */
    id: string;
    /** Provider type (linear, jira, asana, shortcut, trello, monday) */
    provider: WorkSourceProvider;
    /**
     * Reference to the API key. Can be:
     * - A workspace_settings key (e.g. 'linear.api_key')
     * - An environment variable name (e.g. 'PRLT_LINEAR_API_KEY')
     */
    apiKeyRef: string;
    /**
     * Team or project identifier in the external system.
     * e.g. Linear team key 'ENG', Jira project key 'PROJ', Asana project GID.
     */
    teamProjectId: string;
    /**
     * Prefix used for routing ticket keys to this provider.
     * e.g. 'ENG-' means ticket keys starting with 'ENG-' route to this source.
     * Must end with a separator character (typically '-').
     */
    prefix: string;
    /** Optional human-readable label for display purposes */
    label?: string;
}
export interface ProviderSourceValidationError {
    field: string;
    message: string;
}
export declare function validateProviderSourceEntry(entry: Partial<ProviderSourceEntry>): ProviderSourceValidationError[];
/**
 * Load all provider source entries from the database.
 * Returns an empty array if none are configured.
 */
export declare function loadProviderSources(db: Database.Database): ProviderSourceEntry[];
/**
 * Save the full list of provider source entries to the database.
 */
export declare function saveProviderSources(db: Database.Database, sources: ProviderSourceEntry[]): void;
/**
 * Add a new provider source entry. Returns validation errors if invalid,
 * or throws if an entry with the same id already exists.
 */
export declare function addProviderSource(db: Database.Database, entry: ProviderSourceEntry): ProviderSourceValidationError[];
/**
 * Update an existing provider source entry by id.
 * Returns validation errors if the update is invalid, or if the entry is not found.
 */
export declare function updateProviderSource(db: Database.Database, id: string, updates: Partial<Omit<ProviderSourceEntry, 'id'>>): ProviderSourceValidationError[];
/**
 * Remove a provider source entry by id.
 * Returns true if removed, false if not found.
 */
export declare function removeProviderSource(db: Database.Database, id: string): boolean;
/**
 * Get a single provider source entry by id.
 */
export declare function getProviderSourceById(db: Database.Database, id: string): ProviderSourceEntry | null;
/**
 * Resolve which provider source should handle a given ticket key based on
 * its prefix. Matching is case-insensitive and selects the longest matching
 * prefix (most specific match wins).
 *
 * Example: given sources with prefixes ['ENG-', 'PROD-', 'DES-'],
 *   resolveProviderByPrefix(db, 'ENG-123') → source with prefix 'ENG-'
 *   resolveProviderByPrefix(db, 'PROD-456') → source with prefix 'PROD-'
 *   resolveProviderByPrefix(db, 'UNKNOWN-789') → null
 */
export declare function resolveProviderByPrefix(db: Database.Database, ticketKey: string): ProviderSourceEntry | null;
/**
 * Pure function variant that operates on an in-memory list of sources.
 * Useful for testing and batch operations.
 */
export declare function resolveProviderByPrefixFromList(sources: ProviderSourceEntry[], ticketKey: string): ProviderSourceEntry | null;
/**
 * Get all configured prefixes and their provider mappings.
 * Useful for displaying the routing table to the user.
 */
export declare function getRoutingTable(db: Database.Database): Array<{
    prefix: string;
    provider: WorkSourceProvider;
    label: string;
    id: string;
}>;
/**
 * Create or update a provider source entry by id.
 * Used by connect commands to register the provider as a source after authentication.
 * If an entry with the same id exists, it is replaced. Otherwise a new entry is added.
 */
export declare function upsertProviderSource(db: Database.Database, entry: ProviderSourceEntry): ProviderSourceValidationError[];
/**
 * Remove all provider source entries for a given provider type.
 * Used by connect --disconnect to clean up provider sources.
 * Returns the number of entries removed.
 */
export declare function removeProviderSourcesByProvider(db: Database.Database, provider: WorkSourceProvider): number;
/**
 * Resolve the actual API key value from a ProviderSourceEntry's apiKeyRef.
 *
 * Resolution order:
 * 1. If apiKeyRef matches an environment variable name, use its value
 * 2. If apiKeyRef matches a workspace_settings key, use its value
 * 3. Return null if neither resolves
 */
export declare function resolveApiKey(db: Database.Database, entry: ProviderSourceEntry): string | null;
