import { HCS10BaseClient } from './base-client';
import { AIAgentProfile } from '../hcs-11';
import { TransactMessage, HCSMessage } from './types';
/**
 * Represents a connection request between agents
 */
export interface ConnectionRequest {
    id: number;
    requesterId: string;
    requesterTopicId: string;
    targetAccountId: string;
    targetTopicId: string;
    operatorId: string;
    sequenceNumber: number;
    created: Date;
    memo?: string;
    status: 'pending' | 'confirmed' | 'rejected';
}
/**
 * Represents an active connection between agents
 */
export interface Connection {
    connectionTopicId: string;
    targetAccountId: string;
    targetAgentName?: string;
    targetInboundTopicId?: string;
    targetOutboundTopicId?: string;
    status: 'pending' | 'established' | 'needs_confirmation' | 'closed';
    isPending: boolean;
    needsConfirmation: boolean;
    memo?: string;
    created: Date;
    lastActivity?: Date;
    profileInfo?: AIAgentProfile;
    connectionRequestId?: number;
    confirmedRequestId?: number;
    requesterOutboundTopicId?: string;
    inboundRequestId?: number;
    closedReason?: string;
    closeMethod?: string;
    uniqueRequestKey?: string;
    originTopicId?: string;
    processed: boolean;
}
/**
 * Options for the connections manager
 */
export interface ConnectionsManagerOptions {
    logLevel?: 'debug' | 'info' | 'warn' | 'error';
    filterPendingAccountIds?: string[];
    baseClient: HCS10BaseClient;
    silent?: boolean;
}
/**
 * Defines the interface for a connections manager that handles HCS-10 connections
 * This interface represents the public API of ConnectionsManager
 */
export interface IConnectionsManager {
    /**
     * Fetches and processes connection data using the configured client
     * @param accountId - The account ID to fetch connection data for
     * @returns A promise that resolves to an array of Connection objects
     */
    fetchConnectionData(accountId: string): Promise<Connection[]>;
    /**
     * Process outbound messages to track connection requests and confirmations
     * @param messages - The messages to process
     * @param accountId - The account ID that sent the messages
     * @returns Array of connections after processing
     */
    processOutboundMessages(messages: HCSMessage[], accountId: string): Connection[];
    /**
     * Process inbound messages to track connection requests and confirmations
     * @param messages - The messages to process
     * @returns Array of connections after processing
     */
    processInboundMessages(messages: HCSMessage[]): Connection[];
    /**
     * Process connection topic messages to update last activity time
     * @param connectionTopicId - The topic ID of the connection
     * @param messages - The messages to process
     * @returns The updated connection or undefined if not found
     */
    processConnectionMessages(connectionTopicId: string, messages: HCSMessage[]): Connection | undefined;
    /**
     * Adds or updates profile information for a connection
     * @param accountId - The account ID to add profile info for
     * @param profile - The profile information
     */
    addProfileInfo(accountId: string, profile: AIAgentProfile): void;
    /**
     * Gets all connections
     * @returns Array of all connections that should be visible
     */
    getAllConnections(): Connection[];
    /**
     * Gets all pending connection requests
     * @returns Array of pending connection requests
     */
    getPendingRequests(): Connection[];
    /**
     * Gets all active (established) connections
     * @returns Array of active connections
     */
    getActiveConnections(): Connection[];
    /**
     * Gets all connections needing confirmation
     * @returns Array of connections needing confirmation
     */
    getConnectionsNeedingConfirmation(): Connection[];
    /**
     * Gets a connection by its topic ID
     * @param connectionTopicId - The topic ID to look up
     * @returns The connection with the given topic ID, or undefined if not found
     */
    getConnectionByTopicId(connectionTopicId: string): Connection | undefined;
    /**
     * Gets a connection by account ID
     * @param accountId - The account ID to look up
     * @returns The connection with the given account ID, or undefined if not found
     */
    getConnectionByAccountId(accountId: string): Connection | undefined;
    /**
     * Gets all connections for a specific account ID
     * @param accountId - The account ID to look up
     * @returns Array of connections for the given account ID
     */
    getConnectionsByAccountId(accountId: string): Connection[];
    /**
     * Updates or adds a connection
     * @param connection - The connection to update or add
     */
    updateOrAddConnection(connection: Connection): void;
    /**
     * Clears all tracked connections and requests
     */
    clearAll(): void;
    /**
     * Checks if a given connection request has been processed already
     * This uses a combination of topic ID and request ID to uniquely identify requests
     *
     * @param inboundTopicId - The inbound topic ID where the request was received
     * @param requestId - The sequence number (request ID)
     * @returns True if this specific request has been processed, false otherwise
     */
    isConnectionRequestProcessed(inboundTopicId: string, requestId: number): boolean;
    /**
     * Marks a specific connection request as processed
     *
     * @param inboundTopicId - The inbound topic ID where the request was received
     * @param requestId - The sequence number (request ID)
     * @returns True if a matching connection was found and marked, false otherwise
     */
    markConnectionRequestProcessed(inboundTopicId: string, requestId: number): boolean;
    /**
     * Gets pending transactions from a specific connection
     * @param connectionTopicId - The connection topic ID to check for transactions
     * @param options - Optional filtering and retrieval options
     * @returns Array of pending transaction messages sorted by timestamp (newest first)
     */
    getPendingTransactions(connectionTopicId: string, options?: {
        limit?: number;
        sequenceNumber?: string | number;
        order?: 'asc' | 'desc';
    }): Promise<TransactMessage[]>;
    /**
     * Gets the status of a scheduled transaction
     * @param scheduleId - The schedule ID to check
     * @returns Status of the scheduled transaction
     */
    getScheduledTransactionStatus(scheduleId: string): Promise<{
        executed: boolean;
        executedTimestamp?: string;
        deleted: boolean;
        expirationTime?: string;
    }>;
    /**
     * Gets the timestamp of the last message sent by the specified operator on the connection topic
     * @param connectionTopicId - The topic ID to check
     * @param operatorAccountId - The account ID of the operator
     * @returns The timestamp of the last message or undefined if no messages found
     */
    getLastOperatorActivity(connectionTopicId: string, operatorAccountId: string): Promise<Date | undefined>;
}
/**
 * ConnectionsManager provides a unified way to track and manage HCS-10 connections
 * across different applications. It works with both frontend and backend implementations.
 */
export declare class ConnectionsManager implements IConnectionsManager {
    private logger;
    private connections;
    private pendingRequests;
    private profileCache;
    private filterPendingAccountIds;
    private baseClient;
    /**
     * Creates a new ConnectionsManager instance
     */
    constructor(options: ConnectionsManagerOptions);
    /**
     * Fetches and processes connection data using the configured client
     * @param accountId - The account ID to fetch connection data for
     * @returns A promise that resolves to an array of Connection objects
     */
    fetchConnectionData(accountId: string): Promise<Connection[]>;
    /**
     * Checks target agent inbound topics to find confirmations for pending requests
     * that might not be visible in our local messages
     */
    private checkTargetInboundTopicsForConfirmations;
    /**
     * Checks target agents' inbound topics for confirmations of our outbound connection requests
     * This complements checkTargetInboundTopicsForConfirmations by looking for confirmations
     * that might have been sent to the target agent's inbound topic rather than our own
     */
    private checkOutboundRequestsForConfirmations;
    /**
     * Fetches profiles for all connected accounts
     * @param accountId - The account ID making the request
     */
    private fetchProfilesForConnections;
    /**
     * Updates pending connections with inbound topic IDs from profile info
     * @param accountId - The account ID to update connections for
     * @param profile - The profile containing the inbound topic ID
     */
    private updatePendingConnectionsWithProfileInfo;
    /**
     * Fetches activity from active connection topics
     * Updates the lastActivity timestamp for each connection based on latest messages
     * @returns Promise that resolves when all activity has been fetched
     */
    private fetchConnectionActivity;
    /**
     * Checks if an account should be filtered, taking into account existing established connections
     * @param accountId - The account ID to check
     * @returns True if the account should be filtered, false otherwise
     */
    private shouldFilterAccount;
    /**
     * Process outbound messages to track connection requests and confirmations
     * @param messages - The messages to process
     * @param accountId - The account ID that sent the messages
     * @returns Array of connections after processing
     */
    processOutboundMessages(messages: HCSMessage[], accountId: string): Connection[];
    /**
     * Process inbound messages to track connection requests and confirmations
     * @param messages - The messages to process
     * @returns Array of connections after processing
     */
    processInboundMessages(messages: HCSMessage[]): Connection[];
    /**
     * Process connection topic messages to update last activity time
     * @param connectionTopicId - The topic ID of the connection
     * @param messages - The messages to process
     * @returns The updated connection or undefined if not found
     */
    processConnectionMessages(connectionTopicId: string, messages: HCSMessage[]): Connection | undefined;
    /**
     * Adds or updates profile information for a connection
     * @param accountId - The account ID to add profile info for
     * @param profile - The profile information
     */
    addProfileInfo(accountId: string, profile: AIAgentProfile): void;
    /**
     * Gets all connections
     * @returns Array of all connections that should be visible
     */
    getAllConnections(): Connection[];
    /**
     * Gets all pending connection requests
     * @returns Array of pending connection requests
     */
    getPendingRequests(): Connection[];
    /**
     * Helper method to check if there's an established connection with an account
     * @param accountId - The account ID to check
     * @returns True if there's an established connection, false otherwise
     */
    private hasEstablishedConnectionWithAccount;
    /**
     * Gets all active (established) connections
     * @returns Array of active connections
     */
    getActiveConnections(): Connection[];
    /**
     * Gets all connections needing confirmation
     * @returns Array of connections needing confirmation
     */
    getConnectionsNeedingConfirmation(): Connection[];
    /**
     * Gets a connection by its topic ID
     * @param connectionTopicId - The topic ID to look up
     * @returns The connection with the given topic ID, or undefined if not found
     */
    getConnectionByTopicId(connectionTopicId: string): Connection | undefined;
    /**
     * Gets a connection by account ID
     * @param accountId - The account ID to look up
     * @returns The connection with the given account ID, or undefined if not found
     */
    getConnectionByAccountId(accountId: string): Connection | undefined;
    /**
     * Gets all connections for a specific account ID
     * @param accountId - The account ID to look up
     * @returns Array of connections for the given account ID
     */
    getConnectionsByAccountId(accountId: string): Connection[];
    /**
     * Updates or adds a connection
     * @param connection - The connection to update or add
     */
    updateOrAddConnection(connection: Connection): void;
    /**
     * Clears all tracked connections and requests
     */
    clearAll(): void;
    /**
     * Checks if a given connection request has been processed already
     * This uses a combination of topic ID and request ID to uniquely identify requests
     *
     * @param inboundTopicId - The inbound topic ID where the request was received
     * @param requestId - The sequence number (request ID)
     * @returns True if this specific request has been processed, false otherwise
     */
    isConnectionRequestProcessed(inboundTopicId: string, requestId: number): boolean;
    /**
     * Marks a specific connection request as processed
     *
     * @param inboundTopicId - The inbound topic ID where the request was received
     * @param requestId - The sequence number (request ID)
     * @returns True if a matching connection was found and marked, false otherwise
     */
    markConnectionRequestProcessed(inboundTopicId: string, requestId: number): boolean;
    /**
     * Gets pending transactions from a specific connection
     * @param connectionTopicId - The connection topic ID to check for transactions
     * @param options - Optional filtering and retrieval options
     * @returns Array of pending transaction messages sorted by timestamp (newest first)
     */
    getPendingTransactions(connectionTopicId: string, options?: {
        limit?: number;
        sequenceNumber?: string | number;
        order?: 'asc' | 'desc';
    }): Promise<TransactMessage[]>;
    /**
     * Gets the status of a scheduled transaction
     * @param scheduleId - The schedule ID to check
     * @returns Status of the scheduled transaction
     */
    getScheduledTransactionStatus(scheduleId: string): Promise<{
        executed: boolean;
        executedTimestamp?: string;
        deleted: boolean;
        expirationTime?: string;
    }>;
    /**
     * Gets the timestamp of the last message sent by the specified operator on the connection topic
     * @param connectionTopicId - The topic ID to check
     * @param operatorAccountId - The account ID of the operator
     * @returns The timestamp of the last message or undefined if no messages found
     */
    getLastOperatorActivity(connectionTopicId: string, operatorAccountId: string): Promise<Date | undefined>;
}
//# sourceMappingURL=connections-manager.d.ts.map