import { AxiosRequestConfig, AxiosResponse } from 'axios';
export { AxiosRequestConfig, AxiosResponse } from 'axios';

/**
 * NetSuite API Client Types
 * @module @neatsuite/http
 */

/**
 * OAuth 1.0a configuration for NetSuite
 */
interface NetSuiteOAuthConfig {
    consumerKey: string;
    consumerSecret: string;
    tokenKey: string;
    tokenSecret: string;
    realm: string;
}
/**
 * NetSuite client configuration
 */
interface NetSuiteConfig {
    /** OAuth 1.0a configuration */
    oauth: NetSuiteOAuthConfig;
    /** NetSuite account URL ID (e.g., "1234567") */
    accountId: string;
    /** Optional timeout in milliseconds (default: 15000) */
    timeout?: number;
    /** Optional number of retry attempts (default: 3) */
    retries?: number;
    /** Optional custom headers */
    headers?: Record<string, string>;
    /** Enable performance logging (default: false) */
    enablePerformanceLogging?: boolean;
}
/**
 * HTTP methods supported by the client
 */
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
/**
 * Request options for NetSuite API calls
 */
interface NetSuiteRequestOptions {
    /** Full NetSuite API URL */
    url: string;
    /** HTTP method */
    method?: HttpMethod;
    /** Request body for POST/PUT/PATCH requests */
    body?: any;
    /** Additional headers for this request */
    headers?: Record<string, string>;
    /** Override retries for this request */
    retries?: number;
    /** Custom axios config options */
    axiosConfig?: Partial<AxiosRequestConfig>;
}
/**
 * Response from NetSuite API
 */
interface NetSuiteResponse<T = any> {
    /** Response data */
    data: T;
    /** HTTP status code */
    status: number;
    /** Response headers */
    headers: Record<string, string>;
    /** Request duration in milliseconds */
    duration: number;
}
/**
 * NetSuite RESTlet parameters
 */
interface NetSuiteRestletParams {
    /** Script ID */
    script: string | number;
    /** Deploy ID */
    deploy: string | number;
    /** Additional query parameters */
    params?: Record<string, string | number | boolean>;
}
/**
 * Performance measurement result
 */
interface PerformanceResult<T> {
    result: T;
    duration: number;
}
/**
 * NetSuite error response
 */
interface NetSuiteErrorResponse {
    type?: string;
    title?: string;
    status?: number;
    detail?: string;
    'o:errorDetails'?: Array<{
        detail?: string;
        'o:errorCode'?: string;
    }>;
}
/**
 * Custom error class for NetSuite API errors
 */
declare class NetSuiteError extends Error {
    readonly status?: number;
    readonly code?: string;
    readonly details?: NetSuiteErrorResponse;
    readonly response?: AxiosResponse;
    constructor(message: string, status?: number, code?: string, details?: NetSuiteErrorResponse, response?: AxiosResponse);
}
/**
 * Options for retry behavior
 */
interface RetryOptions {
    /** Number of retry attempts */
    retries: number;
    /** Minimum timeout between retries in ms */
    minTimeout?: number;
    /** Maximum timeout between retries in ms */
    maxTimeout?: number;
    /** Factor to multiply timeout by for each retry */
    factor?: number;
    /** Randomize timeout between retries */
    randomize?: boolean;
    /** Custom function to determine if retry should happen */
    shouldRetry?: (error: any) => boolean;
    /** Callback on failed attempt */
    onFailedAttempt?: (error: any) => void;
}
/**
 * Cache options for responses
 */
interface CacheOptions {
    /** Cache TTL in seconds */
    ttl?: number;
    /** Key for caching */
    key?: string;
    /** Whether to use cache */
    enabled?: boolean;
}
/**
 * Request context for middleware
 */
interface RequestContext {
    /** Request configuration */
    config: NetSuiteRequestOptions;
    /** OAuth headers */
    authHeaders: Record<string, string>;
    /** Start time of request */
    startTime: number;
}
/**
 * Middleware function type
 */
type Middleware = (context: RequestContext, next: () => Promise<AxiosResponse>) => Promise<AxiosResponse>;
/**
 * Logger interface for custom logging
 */
interface Logger {
    debug: (message: string, meta?: any) => void;
    info: (message: string, meta?: any) => void;
    warn: (message: string, meta?: any) => void;
    error: (message: string, meta?: any) => void;
}

/**
 * NetSuite API Client
 * @module @neatsuite/http
 */

/**
 * NetSuite API Client
 *
 * @example
 * ```typescript
 * import { NetSuiteClient } from '@neatsuite/http';
 *
 * const client = new NetSuiteClient({
 *   oauth: {
 *     consumerKey: 'your-consumer-key',
 *     consumerSecret: 'your-consumer-secret',
 *     tokenKey: 'your-token-key',
 *     tokenSecret: 'your-token-secret',
 *     realm: 'your-realm'
 *   },
 *   accountId: 'your-account-id'
 * });
 *
 * // Make a RESTlet call
 * const response = await client.restlet({
 *   script: '123',
 *   deploy: '1',
 *   params: { customParam: 'value' }
 * });
 * ```
 */
declare class NetSuiteClient {
    private config;
    private oauth;
    private axiosInstance;
    private middlewares;
    private logger?;
    constructor(config: NetSuiteConfig, logger?: Logger);
    /**
     * Add middleware to the request pipeline
     * @param middleware - Middleware function
     */
    use(middleware: Middleware): void;
    /**
     * Setup axios interceptors for logging
     */
    private setupInterceptors;
    /**
     * Generate OAuth authorization header
     */
    private generateAuthHeader;
    /**
     * Measure performance of an operation
     */
    private measurePerformance;
    /**
     * Execute middleware chain
     */
    private executeMiddlewares;
    /**
     * Make a request to NetSuite API
     *
     * @example
     * ```typescript
     * const response = await client.request({
     *   url: 'https://account.restlets.api.netsuite.com/app/site/hosting/restlet.nl',
     *   method: 'POST',
     *   body: { action: 'search', query: 'customer' }
     * });
     * ```
     */
    request<T = any>(options: NetSuiteRequestOptions): Promise<NetSuiteResponse<T>>;
    /**
     * Build NetSuite RESTlet URL
     */
    private buildRestletUrl;
    /**
     * Make a RESTlet call
     *
     * @example
     * ```typescript
     * const response = await client.restlet({
     *   script: '123',
     *   deploy: '1',
     *   params: { action: 'getCustomer', id: '456' }
     * });
     * ```
     */
    restlet<T = any>(params: NetSuiteRestletParams, options?: Partial<NetSuiteRequestOptions>): Promise<NetSuiteResponse<T>>;
    /**
     * GET request helper
     */
    get<T = any>(url: string, options?: Partial<NetSuiteRequestOptions>): Promise<NetSuiteResponse<T>>;
    /**
     * POST request helper
     */
    post<T = any>(url: string, body?: any, options?: Partial<NetSuiteRequestOptions>): Promise<NetSuiteResponse<T>>;
    /**
     * PUT request helper
     */
    put<T = any>(url: string, body?: any, options?: Partial<NetSuiteRequestOptions>): Promise<NetSuiteResponse<T>>;
    /**
     * PATCH request helper
     */
    patch<T = any>(url: string, body?: any, options?: Partial<NetSuiteRequestOptions>): Promise<NetSuiteResponse<T>>;
    /**
     * DELETE request helper
     */
    delete<T = any>(url: string, options?: Partial<NetSuiteRequestOptions>): Promise<NetSuiteResponse<T>>;
    /**
     * Handle API errors
     */
    static isNetSuiteError(error: any): error is NetSuiteError;
    /**
     * Create error from axios error
     */
    static createError(error: any): NetSuiteError;
}

/**
 * NetSuite API Utilities
 * @module @neatsuite/http
 */
/**
 * Simple in-memory cache for API responses
 */
declare class ResponseCache {
    private cache;
    /**
     * Get cached response
     */
    get<T>(key: string): T | null;
    /**
     * Set cached response
     */
    set(key: string, data: any, ttl: number): void;
    /**
     * Clear cache
     */
    clear(): void;
    /**
     * Remove specific key
     */
    delete(key: string): boolean;
}
/**
 * Rate limiter for API calls
 */
declare class RateLimiter {
    private requests;
    private maxRequests;
    private windowMs;
    constructor(maxRequests?: number, windowMs?: number);
    /**
     * Check if request can be made
     */
    canMakeRequest(): boolean;
    /**
     * Record a request
     */
    recordRequest(): void;
    /**
     * Get remaining requests
     */
    getRemainingRequests(): number;
    /**
     * Get time until next request can be made
     */
    getTimeUntilNextRequest(): number;
}
/**
 * Batch multiple requests together
 */
declare class RequestBatcher<T> {
    private batch;
    private batchTimeout?;
    private batchSize;
    private batchDelay;
    private batchProcessor;
    constructor(batchProcessor: (keys: string[]) => Promise<Map<string, T>>, batchSize?: number, batchDelay?: number);
    /**
     * Add request to batch
     */
    add(key: string): Promise<T>;
    /**
     * Process the current batch
     */
    private processBatch;
}
/**
 * Retry with exponential backoff
 */
declare function retryWithBackoff<T>(fn: () => Promise<T>, options?: {
    maxRetries?: number;
    initialDelay?: number;
    maxDelay?: number;
    factor?: number;
    onRetry?: (attempt: number, error: any) => void;
}): Promise<T>;
/**
 * Create a cache key from request options
 */
declare function createCacheKey(url: string, method: string, params?: any): string;
/**
 * Parse NetSuite error response
 */
declare function parseNetSuiteError(error: any): {
    message: string;
    code?: string;
    details?: any;
};
/**
 * Format NetSuite date
 */
declare function formatNetSuiteDate(date: Date): string;
/**
 * Parse NetSuite date
 */
declare function parseNetSuiteDate(dateString: string): Date;
/**
 * Build query string for NetSuite searches
 */
declare function buildSearchQuery(filters: Record<string, any>): string;
/**
 * Sanitize NetSuite field values
 */
declare function sanitizeFieldValue(value: any): any;
/**
 * Convert NetSuite internal ID to string
 */
declare function toInternalId(id: string | number): string;
/**
 * Validate NetSuite configuration
 */
declare function validateConfig(config: any): string[];

export { type CacheOptions, type HttpMethod, type Logger, type Middleware, NetSuiteClient, type NetSuiteConfig, NetSuiteError, type NetSuiteErrorResponse, type NetSuiteOAuthConfig, type NetSuiteRequestOptions, type NetSuiteResponse, type NetSuiteRestletParams, type PerformanceResult, RateLimiter, RequestBatcher, type RequestContext, ResponseCache, type RetryOptions, buildSearchQuery, createCacheKey, formatNetSuiteDate, parseNetSuiteDate, parseNetSuiteError, retryWithBackoff, sanitizeFieldValue, toInternalId, validateConfig };
