"use strict";
/**
 * Type definitions for infinite message loading functionality
 *
 * Used by useInfiniteMessages hook and related components.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createInfiniteMessagesError = createInfiniteMessagesError;
/**
 * Creates a structured InfiniteMessagesError from an unknown error
 *
 * @param options - Error creation options
 * @returns Structured error object
 */
function createInfiniteMessagesError(options) {
    const { error, defaultMessage = 'An error occurred' } = options;
    // Handle TypeError (typically network errors)
    if (error instanceof TypeError && error.message.includes('fetch')) {
        return {
            code: 'NETWORK_ERROR',
            message: 'Network error occurred. Please check your connection.',
            retryable: true,
            originalError: error,
        };
    }
    // Handle Response objects (server errors)
    if (error instanceof Response) {
        if (error.status >= 500) {
            return {
                code: 'SERVER_ERROR',
                message: 'Server error occurred. Please try again later.',
                retryable: true,
            };
        }
        return {
            code: 'UNKNOWN',
            message: `Request failed with status ${error.status}`,
            retryable: error.status !== 404,
        };
    }
    // Handle SyntaxError (parse errors)
    if (error instanceof SyntaxError) {
        return {
            code: 'PARSE_ERROR',
            message: 'Failed to parse response. Please try again.',
            retryable: true,
            originalError: error,
        };
    }
    // Handle generic Error objects
    if (error instanceof Error) {
        return {
            code: 'UNKNOWN',
            message: error.message || defaultMessage,
            retryable: true,
            originalError: error,
        };
    }
    // Handle unknown error types
    return {
        code: 'UNKNOWN',
        message: defaultMessage,
        retryable: true,
    };
}
