import { Emitter } from "mitt";
enum TASK_STATUS {
    READY = "READY",
    MOVING = "MOVING",
    PROCESSING = "PROCESSING",
    SUCCESS = "SUCCESS",
    FAIL = "FAIL"
}
interface TaskConfig {
    level?: number;
    isPreCondition?: boolean;
    parentTaskId?: string;
    asyncFunction: (Task: any) => Promise<any | void>;
    onReady?: (task: Task, message?: any) => Promise<any | void>;
    onMoving?: (task: Task, message?: any) => Promise<any | void>;
    onSuccess?: (task: Task, message?: any) => Promise<any | void>;
    onFail?: (task: Task, message?: any) => Promise<any | void>;
    onProcessing?: (task: Task, message?: any) => Promise<any | void>;
}
/**
 * ## Task **任务实体**
 * parentTaskId用来处理多层级任务的问题
 * 例如 如果父级任务是前置任务 且 包含了多个子级任务  这个时候 子级任务是永远不会执行 因为有且只能有一个前置任务
 * 前置任务里面的子级任务排在前置任务后面 所以不会执行
 * 这个时候需要用这个parentTaskId进行关系绑定
 * **/
export class Task {
    /** 任务ID **/
    readonly id: string;
    /** 父级任务ID **/
    readonly parentTaskId: string;
    /** 任务执行的异步函数 **/
    readonly asyncFunction: (Task: any) => Promise<any | void>;
    /** 任务优先等级 **/
    readonly level: number;
    /** 任务失败次数 **/
    failTimes: number;
    /** 任务执行成功结果 **/
    result: Array<any>;
    /** 任务执行失败报错信息 **/
    error: any;
    /** 任务状态 **/
    status: TASK_STATUS;
    isPreCondition: boolean;
    constructor(config: TaskConfig);
    /** 任务状态更新 **/
    updateStatus(status: TASK_STATUS, message?: any): Promise<void>;
    /** 执行任务 **/
    execute(): Promise<any>;
}
interface TaskQueueConfig {
    ExecuteTaskTime?: number;
    MaxExecuteTask?: number;
    MaxRetry?: number;
    DelayRetryTime?: number;
    MaxKeepLiveSuccessTask?: number;
    AllowedRetrySystemErrorNames?: Array<string>;
    AllowedRetrySystemErrorMessages?: Array<string>;
    AllowedRetrySystemErrorCodes?: Array<number>;
}
interface CreateTaskParams {
    level?: number;
    isPreCondition?: boolean;
    parentTaskId?: string;
    asyncFunction: (Task: any) => Promise<any | void>;
}
/**
 * ## TaskQueue **任务队列管理**
 * **/
export class TaskQueue {
    readonly emitter: Emitter<any>;
    /** 已经准备好的任务队列 **/
    readonly readyTaskQueue: Map<string, Task>;
    /** 处理中的任务队列 **/
    readonly processingTaskQueue: Map<string, Task>;
    /** 执行成功的任务队列 **/
    readonly successTaskQueue: Map<string, Task>;
    /** 失败的任务队列 **/
    readonly failTaskQueue: Map<string, Task>;
    /** 执行任务的单位时间 **/
    readonly ExecuteTaskTime: number;
    /** 最大可执行的任务数量 **/
    readonly MaxExecuteTask: number;
    /** 最大重试次数 **/
    readonly MaxRetry: number;
    /** 延迟重试时间 单位：毫秒 **/
    readonly DelayRetryTime: number;
    /** 最大保存的执行成功任务数量 **/
    readonly MaxKeepLiveSuccessTask: number;
    /** 需要处理的系统错误  当错误信息匹配的时候  才会进入重试task流程 否则任务不会重试 即任务重试需要满足两个条件：报错+报错信息匹配 **/
    readonly AllowedRetrySystemErrorNames: Array<string>;
    /** 需要处理的系统错误  当错误信息匹配的时候  才会进入重试task流程 否则任务不会重试 即任务重试需要满足两个条件：报错+报错信息匹配 **/
    readonly AllowedRetrySystemErrorMessages: Array<string>;
    /** 需要处理的系统错误  当错误信息匹配的时候  才会进入重试task流程 否则任务不会重试 即任务重试需要满足两个条件：报错+报错信息匹配 **/
    readonly AllowedRetrySystemErrorCodes: Array<number>;
    constructor(config?: TaskQueueConfig);
    /** 创建任务 **/
    createTask(data: CreateTaskParams): Promise<any>;
}
interface BaseErrorParams {
    response: FetchAdapterResponse;
    request: Request;
    requestMeta?: RequestMeta;
    message: string;
    code: number;
    stack?: string;
    cause?: Error;
}
export class BaseError extends Error {
    response: FetchAdapterResponse;
    request: Request;
    requestMeta?: RequestMeta;
    code: number;
    constructor(params: BaseErrorParams);
}
export class HttpStatusError extends BaseError {
    constructor({ code, response, request, requestMeta }: {
        code: number;
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    });
}
interface FetchAdapterConfig {
    baseUrl?: string | Array<string>;
    enableCancelRepeatRequest?: boolean;
    enableResponseHidden?: boolean;
    requestInitConfig?: RequestInit;
    requestInterceptor?: (params: RequestInterceptorParams) => Promise<RequestInterceptorParams>;
    timeout?: number;
    pingTestTimeout?: number;
    responseInterceptor?: ({ response, request, requestMeta }: {
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    }) => Promise<{
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    }>;
    responseErrorInterceptor?: (error: BaseError | Error | any) => Promise<BaseError | Error | any>;
    successStatusCode?: Array<number>;
}
interface FetchAdapterRequestConfig {
    url: string;
    requestInitConfig?: RequestInit;
    params?: BodyInit | null;
    enableCancelRepeatRequest?: boolean;
}
interface RequestMeta {
    requestSentAt?: number;
    requestCompleteAt?: number;
    requestWaitingTime?: number;
}
interface RequestInterceptorParams {
    url: string;
    config: RequestInit;
    requestMeta?: RequestMeta;
}
/**
 * ## FetchAdapterResponse **http响应体**
 * **/
export class FetchAdapterResponse extends Response {
    constructor(body?: BodyInit | null, init?: ResponseInit);
    /** 将headers转换成json形式 **/
    getTransformHeaders(): Promise<Object>;
}
/**
 * ## FetchAdapter **http适配器**
 * **/
export class FetchAdapter {
    readonly baseRequestConfig: RequestInit;
    readonly requestTaskControllerList: Map<string, AbortController>;
    readonly enableCancelRepeatRequest: boolean;
    baseUrl: Array<string>;
    readonly successStatusCode: Array<number>;
    readonly enableResponseHidden: boolean;
    readonly timeout: number;
    readonly pingTestTimeout: number;
    constructor(config?: FetchAdapterConfig);
    /** 测速 **/
    runPingTest(): Promise<void>;
    /** 获取动态url **/
    getDynamicBaseUrl(): Promise<string>;
    /** 对url以及query参数进行处理 **/
    makeUrl(originalUrl: any, params?: Object | null): Promise<string>;
    /** 对body参数进行处理 **/
    makeBody(params?: BodyInit | null): Promise<BodyInit | null>;
    /** 生成请求token 用来取消重复的请求 **/
    generateRequestToken(config: FetchAdapterRequestConfig): Promise<string>;
    /** 生成取消请求的控制信号 **/
    getRequestSignal(config: FetchAdapterRequestConfig, timeout?: number): Promise<AbortSignal | null>;
    /** 构造基本的请求方法 **/
    request(config: FetchAdapterRequestConfig): Promise<{
        response: FetchAdapterResponse;
        request: Request;
    }>;
    get(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean): Promise<any>;
    post(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean): Promise<any>;
    put(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean): Promise<any>;
    delete(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean): Promise<any>;
    search(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean): Promise<any>;
    patch(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean): Promise<any>;
}
interface NextNetworkConfig {
    taskQueue?: TaskQueue;
    taskQueueConfig?: TaskQueueConfig;
    fetchAdapter?: FetchAdapter;
    fetchAdapterConfig?: FetchAdapterConfig;
    enablePingTest?: boolean;
}
/**
 * ## NextNetwork **网络管理器**
 * **/
export class NextNetwork {
    readonly taskQueue: TaskQueue;
    readonly fetchAdapter: FetchAdapter;
    readonly enablePingTest?: boolean;
    constructor(config?: NextNetworkConfig);
    createPreConditionTask({ asyncFunction }: {
        asyncFunction: (Task: any) => Promise<any | void>;
    }): Promise<any>;
    request(fetchAdapterRequestConfig: FetchAdapterRequestConfig, parentTaskId?: string): Promise<{
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    }>;
    get(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean, parentTaskId?: string): Promise<{
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    }>;
    post(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean, parentTaskId?: string): Promise<{
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    }>;
    put(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean, parentTaskId?: string): Promise<{
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    }>;
    delete(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean, parentTaskId?: string): Promise<{
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    }>;
    search(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean, parentTaskId?: string): Promise<{
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    }>;
    patch(url: string, params?: Object | BodyInit | null, enableCancelRepeatRequest?: boolean, parentTaskId?: string): Promise<{
        response: FetchAdapterResponse;
        request: Request;
        requestMeta?: RequestMeta;
    }>;
}
/**
 * ## ResponseHelpers **Response工具类**
 * **/
export class ResponseHelpers {
    /** 将json重新封装成FetchAdapterResponse对象 **/
    static repackResponseByJson(json: Object, fetchAdapterResponse: FetchAdapterResponse): Promise<FetchAdapterResponse>;
}
/**
 * ## 暴露的接口方法对象
 * ## {Task, TaskQueue, FetchAdapter, NextNetwork, FetchAdapterResponse, BaseError, HttpStatusError}
 * 1. Task **任务实体**<br>
 * 作用：定义了一个任务实体上应该有的方法
 * 2. TaskQueue **任务队列管理**<br>
 * 作用：管理每个任务的执行状态和重试报错等机制
 * 3. FetchAdapter **http适配器**<br>
 * 作用：请求请求接口数据的方法 可以根据自己的实际情况继承适配器再作修改
 * 4. NextNetwork **网络管理器**<br>
 * 作用：对任务队列和http适配器集中调度
 * 5. FetchAdapterResponse **http响应体**<br>
 * 作用：统一的响应体结构
 * 6. BaseError **基础错误类**<br>
 * 作用：错误信息继承的基础对象
 * 7. HttpStatusError **http code 错误**<br>
 * 作用：默认 http status 不在 successStatusCode 列表里面 则会报错
 * 8. ResponseHelpers **response工具类**<br>
 * 作用：提供一些Response辅助的工具类
 * **/
declare const index: {
    Task: Task;
    TaskQueue: TaskQueue;
    FetchAdapter: FetchAdapter;
    NextNetwork: NextNetwork;
    FetchAdapterResponse: FetchAdapterResponse;
    BaseError: BaseError;
    HttpStatusError: HttpStatusError;
    ResponseHelpers: ResponseHelpers;
};
export default index;

//# sourceMappingURL=types.d.ts.map
