/**
 * Loan Query Module
 *
 * Responsible for:
 * - Querying loan data from subgraph
 * - Enriching loans with Bitcoin balance data
 * - Caching query results for performance
 * - Supporting pagination for large result sets
 *
 * Uses the existing DiamondHandsGraphClient for subgraph queries
 */
import { Result } from "../../types/result";
import { SDKError } from "../../utils/error-handler";
import type { BitcoinOperations } from "../bitcoin/bitcoin-operations.module";
import type { Cache } from "../cache/cache-manager.module";
import type { LoanData, LoanDataDetail, PaginatedLoansResponse } from "../../interfaces/chunks/loan-operations.i";
import type { LoanEvents, LoanEventsFilter } from "../../types/event-types";
import { DiamondHandsGraphClient } from "@graphs/diamond-hands";
import { type Provider } from "ethers";
/**
 * Loan query filters
 */
export interface LoanQueryFilters {
    /** Filter by borrower address */
    borrower?: string;
    /** Filter by status */
    status?: number;
    /** Filter by minimum collateral ratio (BPS) */
    minCollateralRatio?: number;
    /** Filter by maximum collateral ratio (BPS) */
    maxCollateralRatio?: number;
    /** Order by field */
    orderBy?: "createdAt" | "lastUpdatedAt" | "ucdDebt";
    /** Order direction */
    orderDirection?: "asc" | "desc";
}
/**
 * Pagination parameters
 */
export interface PaginationParams {
    /** Page number (0-indexed) */
    page: number;
    /** Number of items per page */
    pageSize: number;
}
/**
 * Loan Query configuration
 */
export interface LoanQueryConfig {
    /** Subgraph client for queries */
    graphClient: DiamondHandsGraphClient;
    /** Bitcoin operations for balance enrichment */
    bitcoinOperations: BitcoinOperations;
    /** Ethereum provider for PKP public key retrieval */
    provider?: Provider;
    /** PositionManagerCoreModule address — used as fallback vault address source for Chipotle loans */
    positionManagerCoreAddress?: string;
    /** Cache for loan query results (keyed by PKP ID) */
    cache?: Cache<LoanData>;
    /** Enable debug logging */
    debug?: boolean;
    /** Default page size for pagination */
    defaultPageSize?: number;
}
/**
 * Loan Query Module
 *
 * Handles all loan data queries with caching and balance enrichment
 */
export declare class LoanQuery {
    private readonly config;
    private readonly defaultPageSize;
    constructor(config: LoanQueryConfig);
    /**
     * Get loan by position ID
     *
     * @param positionId - Position ID
     * @param enrichBalance - Whether to enrich with Bitcoin balance
     * @returns Detailed loan data
     */
    getLoanById(positionId: string, enrichBalance?: boolean): Promise<Result<LoanDataDetail | null, SDKError>>;
    /**
     * Get loan by PKP ID
     *
     * @param pkpId - PKP token ID
     * @param enrichBalance - Whether to enrich with Bitcoin balance
     * @returns Loan data
     */
    getLoanByPkpId(pkpId: string, enrichBalance?: boolean): Promise<Result<LoanDataDetail | null, SDKError>>;
    /**
     * Get loans with filters and pagination
     *
     * @param filters - Query filters
     * @param pagination - Pagination parameters
     * @returns Paginated loans response
     */
    getLoans(filters?: LoanQueryFilters, pagination?: PaginationParams): Promise<Result<PaginatedLoansResponse, SDKError>>;
    /**
     * Get loans with BTC balance data from Bitcoin network
     *
     * Same as getLoans but includes actual Bitcoin balance for each position's vault.
     * Queries BTC balances in parallel for performance.
     *
     * @param filters - Query filters
     * @param pagination - Pagination parameters
     * @returns Paginated loans response with BTC balance data
     */
    getLoansWithBtc(filters?: LoanQueryFilters, pagination?: PaginationParams): Promise<Result<PaginatedLoansResponse, SDKError>>;
    /**
     * Enrich loans with vault addresses derived from PKP public keys
     *
     * @param loans - Array of loans to enrich
     * @returns Enriched loans with vault addresses for all networks
     */
    private enrichLoansWithVaultAddresses;
    /**
     * Map numeric status to string for subgraph queries
     */
    private mapStatusToString;
    /**
     * Map string status to numeric for filtering
     */
    private mapStringToStatus;
    /**
     * Validate if a string is a valid loan status
     */
    private isValidStatus;
    /**
     * Get loans for a borrower
     *
     * @param borrower - Borrower address
     * @param pagination - Pagination parameters
     * @returns Paginated loans for borrower
     */
    getLoansByBorrower(borrower: string, pagination?: PaginationParams, orderBy?: "createdAt" | "lastUpdatedAt" | "ucdDebt", orderDirection?: "asc" | "desc"): Promise<Result<PaginatedLoansResponse, SDKError>>;
    /**
     * Get active loans (status = ACTIVE)
     *
     * @param pagination - Pagination parameters
     * @returns Paginated active loans
     */
    getActiveLoans(pagination?: PaginationParams): Promise<Result<PaginatedLoansResponse, SDKError>>;
    /**
     * Get loans by state/status
     *
     * @param state - Loan state (PENDING_DEPOSIT, PENDING_MINT, ACTIVE, EXPIRED, LIQUIDATABLE, LIQUIDATED, REPAID, CLOSED)
     * @param pagination - Pagination parameters
     * @returns Paginated loans matching the specified state
     */
    getLoansByState(state: string, pagination?: PaginationParams): Promise<Result<PaginatedLoansResponse, SDKError>>;
    /**
     * Enrich a loan with current Bitcoin balance
     *
     * Note: btcAmount field removed - balance is now queried on-chain via lit-actions with signature validation
     * This method is kept for potential future use but no longer sets btcAmount
     */
    private enrichLoanWithBalance;
    /**
     * Get all events for a loan position
     *
     * Retrieves complete event history including:
     * - Payments (full repayments, partial payments, extension fees)
     * - Status updates with reasons
     * - Liquidation event (if liquidated)
     * - UCD mint events
     * - Community fee distributions
     *
     * @param positionId - Position ID to query events for
     * @param filter - Optional filters (date range, event types, etc.)
     * @returns Complete event history for the position
     *
     * @example
     * ```typescript
     * // Get all events
     * const result = await loanQuery.getLoanEvents('0x123...');
     *
     * // Get only payment events
     * const paymentsOnly = await loanQuery.getLoanEvents('0x123...', {
     *   eventTypes: ['payment']
     * });
     *
     * // Get events in date range
     * const recent = await loanQuery.getLoanEvents('0x123...', {
     *   fromTimestamp: '1640000000',
     *   toTimestamp: '1650000000'
     * });
     * ```
     */
    getLoanEvents(positionId: string, filter?: LoanEventsFilter): Promise<Result<LoanEvents, SDKError>>;
    /**
     * Clear loan cache
     *
     * @param pkpId - PKP ID to clear, or undefined to clear all
     */
    clearCache(pkpId?: string): void;
    /**
     * Get cache statistics
     */
    getCacheStats(): import("../cache/cache-manager.module").CacheStats | null;
}
/**
 * Factory function to create a LoanQuery instance
 */
export declare function createLoanQuery(config: LoanQueryConfig): Result<LoanQuery, SDKError>;
