import type { IModule } from '@e-mc/types/lib';
import type { UploadContent } from '@e-mc/types/lib/cloud';
import type { AuthValue } from '@e-mc/types/lib/http';

import type { Readable } from 'node:stream';

declare namespace util {
    interface CreateKeyAndBodyOptions {
        errorCallback?: FunctionReturn<void>;
        descendantsGroup?: string[];
        flags?: number;
        chunkSize?: number;
        mimeType?: string;
    }

    function readableAsBuffer(from: Readable): Promise<Buffer | null>;
    function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], options: CreateKeyAndBodyOptions): [string[], T[], string[]];
    function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], errorCallback: FunctionReturn<void>, flags?: number): [string[], T[], string[]];
    /** @deprecated options */
    function createKeyAndBody<T = Buffer>(filename: string, items: UploadContent[], chunkSize?: number | string | FunctionReturn<void>, errorCallback?: FunctionReturn<void> | number, flags?: number, descendantsGroup?: string[]): [string[], T[], string[]];
    function createErrorHandler(instance: IModule, service: string, bucket: string): (err: unknown) => void;
    function generateFilename(filename: string): (i: number) => [string, boolean];
    function getBasicAuth(auth: AuthValue): string;
    function getBasicAuth(username: unknown, password?: unknown): string;
    function hasBasicAuth(value: string): boolean;
    function intoArray<T>(value: T | undefined | null): (T extends Array<infer U> ? U[] : T[]) | null;
    function formatError(title: string | { service: string }, message: string, hint?: string): Error;
}

export = util;