import type { AuthValue } from '@e-mc/types/lib/http';
import type { HttpProxySettings } from '@e-mc/types/lib/settings';

import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'node:http';
import type { Readable, Writable } from 'node:stream';

type OutgoingHeaders = OutgoingHttpHeaders | Headers;

declare namespace util {
    function parseHeader(headers: IncomingHttpHeaders | OutgoingHttpHeaders, name: "cache-control"): string[] | undefined;
    function parseHeader(headers: IncomingHttpHeaders, name: "expires" | "date" | "age"): number | undefined;
    function parseHeader(headers: IncomingHttpHeaders, name: "content-disposition"): string | undefined;
    function parseHeader<T extends string | string[] | number>(headers: IncomingHttpHeaders, name: string): T | undefined;
    /** @deprecated copyHeaders (rename) */
    function parseOutgoingHeaders(headers: OutgoingHeaders | undefined, ...ignore: string[]): OutgoingHttpHeaders | undefined;
    function copyHeaders(headers: OutgoingHeaders | undefined, ...ignore: string[]): OutgoingHttpHeaders | undefined;
    function normalizeHeaders(headers: OutgoingHeaders): OutgoingHttpHeaders;
    function getBasicAuth(auth: AuthValue): string;
    function getBasicAuth(username: unknown, password?: unknown): string;
    function hasBasicAuth(value: string): boolean;
    function checkRetryable(err: unknown): boolean;
    function isRetryable(value: number, timeout?: boolean): boolean;
    function parseHttpProxy(value?: string, ignoreEnv?: boolean): HttpProxySettings | undefined;
    function trimPath(value: string, char?: string): string;
    function asInt(value: unknown): number;
    function asFloat(value: unknown): number;
    function fromSeconds(value: unknown): number;
    function fromURL(url: URL, value: string): string;
    function fromStatusCode(value: number | string): string;
    function getTransferRate(length: number, timeMs: number, unitSeparator?: string): string;
    function hasSameStat(src: string, dest: string, keepEmpty?: boolean): boolean;
    function hasSize(value: string, keepEmpty?: boolean): boolean;
    function getSize(value: string, diskUsed?: boolean): number;
    function byteLength(value: Bufferable, encoding?: BufferEncoding): number;
    function cleanupStream(target: Readable | Writable, pathname?: string): void;
}

export = util;