export declare interface AnyFunc {
    (...args: any[]): any;
    [key: keyof any]: any;
}

export declare interface Caught {
    config: Config;
    hooksMap: HooksMap;
    scheduler: CaughtScheduler;
    createCustomInsert: CreateCustomInsert;
    proxyCaught: ProxyCaught;
}

export declare interface CaughtScheduler {
    pendingInsertInfo(info: Info): void;
    createCustomInsert: CreateCustomInsert;
    retryHandler(): void;
    stop: boolean;
}

export declare interface Config {
    sameLimit: number;
    retry: boolean;
    retryTime: number;
    failMaxNum: number;
    listeners: boolean | {
        jsError: boolean;
        staticError: boolean;
        promiseRection: boolean;
    };
    errorHandler: ErrorHandler;
    plugins?: Plugin_2[];
    sync: boolean;
}

declare function createCaught(rawConfig: Config): {
    createCustomInsert: CreateCustomInsert;
    proxyCaught: ProxyCaught;
} | undefined;
export default createCaught;

export declare interface CreateCustomInsert {
    (type: string, flag: string, extra?: any): (info: CustomInfo) => void;
}

export declare type CustomInfo = Pick<Info, Exclude<keyof Info, 'type' | 'flag'>>;

export declare interface ErrorHandler {
    (info: InfoList, notify: (result: any) => void): any;
}

export declare class HookArray<T> extends Array<T> {
    pluginNameList?: string[];
}

export declare enum HookNames {
    ADDHOOK = "addInfo",
    SUCCESSHOOK = "success",
    FAILHOOK = "fail",
    SCHEDULABLEHOOK = "schedulable",
    JSERRORHOOK = "jsError",
    STATICERRORHOOK = "staticError",
    PROMISERECTIONHOOK = "promiseRejection"
}

export declare type HooksMap = {
    [key in HookNames]: HookArray<HookType[key]>;
};

export declare type HookType = {
    [HookNames.ADDHOOK]: (info?: Info) => Meta | void;
    [HookNames.JSERRORHOOK]: (info?: Info, e?: Event) => Meta | void;
    [HookNames.STATICERRORHOOK]: (info?: Info, e?: Event) => Meta | void;
    [HookNames.PROMISERECTIONHOOK]: (info?: Info, e?: Event) => Meta | void;
    [HookNames.SUCCESSHOOK]: (InfoList?: InfoList, index?: number) => void;
    [HookNames.FAILHOOK]: (InfoList?: InfoList, index?: number) => void;
    [HookNames.SCHEDULABLEHOOK]: (createCustomInsert?: CreateCustomInsert) => void;
};

export declare interface Info {
    type: string;
    flag: string;
    meta?: Meta | Meta[];
    count?: number;
    error?: any;
    message?: string;
    filename?: string;
    lineno?: number;
    colno?: number;
    time?: number;
}

export declare class InfoList extends Array<Info> {
    __waiting__?: boolean;
}

export declare interface Meta {
    [key: keyof any]: any;
}

declare interface Plugin_2 {
    apply(register: Register): void;
}
export { Plugin_2 as Plugin }

export declare interface ProxyCaught {
    <T extends AnyFunc>(rawFunc: T, config: ProxyConfig): (this: any, ...args: Parameters<T>) => any;
}

export declare type ProxyConfig = {
    flag: any;
    withArgs?: boolean;
    others?: any;
} | string;

export declare type Register = {
    [key in HookNames]: (pluginName: string, hook: HookType[key]) => void;
};

export declare type ValueOf<T> = T[keyof T];

export { }
