import { PhantomClient } from '@phantom/client';
export { PhantomClient } from '@phantom/client';

/**
 * Complete session data stored on disk
 *
 * Note: SSO flow uses stamper keys for API authentication, not OAuth tokens
 */
interface SessionData {
    walletId: string;
    organizationId: string;
    authUserId: string;
    /** App/client ID used during authentication (for quote API key headers) */
    appId?: string;
    stamperKeys: {
        publicKey: string;
        secretKey: string;
    };
    createdAt: number;
    updatedAt: number;
}

/**
 * SessionManager orchestrates the complete session lifecycle:
 * - Loads existing sessions from storage
 * - Handles authentication when needed
 * - Creates and manages PhantomClient instances
 * - Provides session data access
 */

/**
 * Configuration options for SessionManager
 */
interface SessionManagerOptions {
    /** Base URL for OAuth authorization server (default: https://auth.phantom.app or PHANTOM_AUTH_BASE_URL env var) */
    authBaseUrl?: string;
    /** Base URL for Phantom Connect (default: https://connect.phantom.app or PHANTOM_CONNECT_BASE_URL env var) */
    connectBaseUrl?: string;
    /** Base URL for Phantom API (default: https://api.phantom.app or PHANTOM_API_BASE_URL env var) */
    apiBaseUrl?: string;
    /** Port for local OAuth callback server (default: 8080 or PHANTOM_CALLBACK_PORT env var) */
    callbackPort?: number;
    /** Path for OAuth callback (default: /callback or PHANTOM_CALLBACK_PATH env var) */
    callbackPath?: string;
    /** Application identifier prefix (default: phantom-mcp) */
    appId?: string;
    /** Directory to store session data (default: ~/.phantom-mcp) */
    sessionDir?: string;
}
/**
 * SessionManager handles session lifecycle, auto-authentication, and PhantomClient creation
 *
 * Usage:
 * ```typescript
 * const manager = new SessionManager();
 * await manager.initialize(); // Loads session or authenticates
 * const client = manager.getClient();
 * const session = manager.getSession();
 * ```
 */
declare class SessionManager {
    private readonly authBaseUrl;
    private readonly connectBaseUrl?;
    private readonly apiBaseUrl;
    private readonly callbackPort;
    private readonly callbackPath;
    private readonly appId;
    private readonly storage;
    private readonly logger;
    private session;
    private client;
    private resolveAppId;
    /**
     * Creates a new SessionManager
     *
     * @param options - Configuration options
     */
    constructor(options?: SessionManagerOptions);
    /**
     * Initializes the session manager
     * Loads existing session or authenticates if needed
     *
     * @throws Error if authentication fails
     */
    initialize(): Promise<void>;
    /**
     * Returns the initialized PhantomClient
     *
     * @returns PhantomClient instance
     * @throws Error if not initialized
     */
    getClient(): PhantomClient;
    /**
     * Returns the current session data
     *
     * @returns Current session data
     * @throws Error if not initialized
     */
    getSession(): SessionData;
    /**
     * Resets the session by clearing stored data and re-authenticating
     *
     * @throws Error if authentication fails
     */
    resetSession(): Promise<void>;
    /**
     * Executes the SSO flow and creates a new session
     * Steps:
     * 1. Execute SSO flow to get wallet/org IDs and stamper keypair
     * 2. Create SessionData with SSO result and stamper keys
     * 3. Save to storage
     * 4. Create PhantomClient
     *
     * Note: Stamper keypair is generated during SSO flow and public key is sent to auth server
     *
     * @throws Error if SSO flow fails
     */
    private authenticate;
    /**
     * Creates a PhantomClient instance from the current session
     * Steps:
     * 1. Create ApiKeyStamper with session keypair
     * 2. Create PhantomClient with stamper, organizationId, and app headers
     * 3. Set walletType to 'user-wallet'
     *
     * @throws Error if session is not available
     */
    private createClient;
}

declare class Logger {
    private context;
    constructor(context?: string);
    /**
     * Private method to write to stderr with proper formatting
     */
    private log;
    /**
     * Log info message
     */
    info(message: string): void;
    /**
     * Log error message
     */
    error(message: string): void;
    /**
     * Log warning message
     */
    warn(message: string): void;
    /**
     * Log debug message (only if DEBUG or PHANTOM_MCP_DEBUG env var is set)
     */
    debug(message: string): void;
    /**
     * Create a child logger with combined context
     * Example: parent context "MCP" + child "Transport" = "MCP:Transport"
     */
    child(childContext: string): Logger;
}

/**
 * MCP Tool types and interfaces
 */

/**
 * Context provided to tool handlers
 */
interface ToolContext {
    /** Authenticated PhantomClient instance */
    client: PhantomClient;
    /** Current session data */
    session: SessionData;
    /** Logger instance for this tool */
    logger: Logger;
}
/**
 * JSON Schema for MCP tool input validation
 */
interface ToolInputSchema {
    type: "object";
    properties: Record<string, unknown>;
    required?: string[];
}
/**
 * MCP Tool annotations describing safety and behavior characteristics.
 * See: https://modelcontextprotocol.io/docs/concepts/tools#tool-annotations
 */
interface ToolAnnotations {
    /** If true, the tool only reads data and has no side effects */
    readOnlyHint?: boolean;
    /** If true, the tool may perform destructive or irreversible actions (e.g. sending transactions) */
    destructiveHint?: boolean;
    /** If true, calling the tool repeatedly with the same inputs has the same effect as calling it once */
    idempotentHint?: boolean;
    /** If true, the tool may interact with external systems outside the local environment */
    openWorldHint?: boolean;
}
/**
 * MCP Tool definition
 */
interface ToolHandler {
    /** Tool name (used in tool calls) */
    name: string;
    /** Tool description (shown to LLM) */
    description: string;
    /** JSON schema for input validation */
    inputSchema: ToolInputSchema;
    /** Safety and behavior annotations */
    annotations?: ToolAnnotations;
    /** Tool handler function */
    handler: (params: Record<string, unknown>, context: ToolContext) => Promise<unknown>;
}

/**
 * MCP Tools Registry
 *
 * This module exports all available MCP tools for the Phantom wallet service.
 */

/**
 * Array of all available tools
 */
declare const tools: ToolHandler[];

export { SessionData, SessionManager, ToolContext, ToolHandler, tools };
