import ArrayList from "@ohos:util.ArrayList";
import type { HttpConverter } from '../converter/HttpConverter';
import { JsonConverter } from "@normalized:N&&&@yic/http/src/main/ets/converter/JsonConverter&1.0.1";
import type { Interceptor } from '../interector/Interceptor';
import { DefaultTaskDispatch } from "@normalized:N&&&@yic/http/src/main/ets/task/DefaultTaskDispatch&1.0.1";
import type { TaskDispatch } from '../task/TaskDispatch';
/**
 * @ProjectName : HarmonyUtilSdk
 * @FileName : HttpConfig
 * @Author : yic
 * @Time : 2024/6/20 15:32
 * @Description : 单例模式配置请求信息
 */
export class HttpConfig {
    host: string = '';
    private connectTimeout: number = 30000;
    private readTimeout: number = 30000;
    private interceptorList: ArrayList<Interceptor> = new ArrayList();
    private static INSTANCE: HttpConfig;
    private converter: HttpConverter = new JsonConverter();
    private taskDispatch: TaskDispatch = new DefaultTaskDispatch();
    private constructor() {
    }
    static getInstance(): HttpConfig {
        if (this.INSTANCE == null) {
            this.INSTANCE = new HttpConfig();
        }
        return this.INSTANCE;
    }
    getHost(): string {
        return this.host;
    }
    config(host?: string, config?: (net: HttpConfig) => void) {
        this.host = host;
        config(this);
    }
    addInterceptor(interceptor: Interceptor) {
        this.interceptorList.add(interceptor);
    }
    getInterceptor(index: number): Interceptor {
        if (index >= 0 && index < this.interceptorList.length) {
            return this.interceptorList[index];
        }
        else {
            null;
        }
    }
    setConnectTimeout(connectTimeout: number) {
        this.connectTimeout = connectTimeout;
    }
    getConnectTimeout(): number {
        return this.connectTimeout;
    }
    setReadTimeout(readTimeout: number) {
        this.readTimeout = readTimeout;
    }
    getReadTimeout(): number {
        return this.readTimeout;
    }
    setConverter(converter: HttpConverter) {
        if (converter) {
            this.converter = converter;
        }
    }
    getConverter(): HttpConverter {
        return this.converter;
    }
    setTaskDispatch(taskDispatch: TaskDispatch) {
        if (taskDispatch) {
            this.taskDispatch = taskDispatch;
        }
    }
    getTaskDispatch(): TaskDispatch {
        return this.taskDispatch;
    }
}
