import { SerializableError } from '../../../models/SerializableError.js';
/**
 * Base class for all HTTP engine errors
 */
export class HttpEngineError extends SerializableError {
    category;
    constructor(message, code, category = 'general') {
        super(message, code);
        this.category = category;
    }
}
/**
 * Connection-related errors
 */
export class ConnectionError extends HttpEngineError {
    connectionType;
    constructor(message, code, connectionType = 'direct') {
        super(message, code, 'connection');
        this.connectionType = connectionType;
    }
}
/**
 * Authentication-related errors
 */
export class AuthenticationError extends HttpEngineError {
    authType;
    constructor(message, code, authType = 'request') {
        super(message, code, 'authentication');
        this.authType = authType;
    }
}
/**
 * Message building errors
 */
export class MessageBuilderError extends HttpEngineError {
    component;
    constructor(message, code, component = 'headers') {
        super(message, code, 'message');
        this.component = component;
    }
}
/**
 * Response parsing errors
 */
export class ResponseParsingError extends HttpEngineError {
    parsingStage;
    constructor(message, code, parsingStage = 'headers') {
        super(message, code, 'parsing');
        this.parsingStage = parsingStage;
    }
}
/**
 * Timeout errors
 */
export class TimeoutError extends HttpEngineError {
    timeoutType;
    constructor(message, code, timeoutType = 'request') {
        super(message, code, 'timeout');
        this.timeoutType = timeoutType;
    }
}
/**
 * Proxy-related errors
 */
export class ProxyError extends HttpEngineError {
    proxyStage;
    name = 'ProxyError';
    constructor(message, code, proxyStage = 'connection') {
        super(message, code, 'proxy');
        this.proxyStage = proxyStage;
    }
}
/**
 * Proxy authentication error
 */
export class ProxyAuthenticationError extends HttpEngineError {
    response;
    head;
    name = 'ProxyAuthenticationError';
    constructor(message, code, response, head) {
        super(message, code, 'proxy');
        this.response = response;
        this.head = head;
    }
}
/**
 * Payload-related errors
 */
export class PayloadError extends HttpEngineError {
    payloadType;
    constructor(message, code, payloadType = 'validation') {
        super(message, code, 'payload');
        this.payloadType = payloadType;
    }
}
/**
 * URL parsing errors
 */
export class UrlParsingError extends HttpEngineError {
    url;
    constructor(message, url, code) {
        super(message, code, 'url');
        this.url = url;
    }
}
/**
 * Configuration errors
 */
export class ConfigurationError extends HttpEngineError {
    configType;
    constructor(message, code, configType = 'request') {
        super(message, code, 'configuration');
        this.configType = configType;
    }
}
/**
 * Error factory for creating specific error types
 */
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class HttpEngineErrorFactory {
    /**
     * Create a connection error
     */
    static connectionError(message, code, connectionType) {
        return new ConnectionError(message, code, connectionType);
    }
    /**
     * Create an authentication error
     */
    static authenticationError(message, code, authType) {
        return new AuthenticationError(message, code, authType);
    }
    /**
     * Create a message builder error
     */
    static messageBuilderError(message, code, component) {
        return new MessageBuilderError(message, code, component);
    }
    /**
     * Create a response parsing error
     */
    static responseParsingError(message, code, parsingStage) {
        return new ResponseParsingError(message, code, parsingStage);
    }
    /**
     * Create a timeout error
     */
    static timeoutError(message, code, timeoutType) {
        return new TimeoutError(message, code, timeoutType);
    }
    /**
     * Create a proxy error
     */
    static proxyError(message, code, proxyStage) {
        return new ProxyError(message, code, proxyStage);
    }
    /**
     * Create a payload error
     */
    static payloadError(message, code, payloadType) {
        return new PayloadError(message, code, payloadType);
    }
    /**
     * Create a URL parsing error
     */
    static urlParsingError(message, url, code) {
        return new UrlParsingError(message, url, code);
    }
    /**
     * Create a configuration error
     */
    static configurationError(message, code, configType) {
        return new ConfigurationError(message, code, configType);
    }
    /**
     * Convert a generic error to an HTTP engine error
     */
    static fromError(error, category = 'general') {
        if (error instanceof HttpEngineError) {
            return error;
        }
        return new HttpEngineError(error.message, undefined, category);
    }
    /**
     * Create a connection timeout error
     */
    static connectionTimeout(timeoutMs) {
        return new TimeoutError(`Connection timeout after ${timeoutMs}ms`, 408, 'connection');
    }
    /**
     * Create a request timeout error
     */
    static requestTimeout(timeoutMs) {
        return new TimeoutError(`Request timeout after ${timeoutMs}ms`, 408, 'request');
    }
    /**
     * Create a proxy authentication error
     */
    static proxyAuthRequired(res, head) {
        return new ProxyAuthenticationError('Proxy authentication required', 407, res, head);
    }
    /**
     * Create a proxy authentication failed error
     */
    static proxyAuthFailed() {
        return new AuthenticationError('Proxy authentication failed', 407, 'proxy');
    }
    /**
     * Create a proxy configuration error
     */
    static proxyConfigError(message) {
        return new ProxyError(message, 400, 'configuration');
    }
    /**
     * Create a payload serialization error
     */
    static payloadSerializationError(message) {
        return new PayloadError(message, 400, 'serialization');
    }
    /**
     * Create an unsupported payload error
     */
    static unsupportedPayload(payloadType) {
        return new PayloadError(`Unsupported payload type: ${payloadType}`, 400, 'unsupported');
    }
}
//# sourceMappingURL=HttpEngineErrors.js.map