import { HttpRequest, HttpResponse, HttpErrorResponse, HttpClient, HttpInterceptor, HttpHandler, HttpEvent } from '@angular/common/http';
import * as i0 from '@angular/core';
import { InjectionToken } from '@angular/core';
import { SdCacheOption } from '@sdcorejs/angular/services/cache';
import { Observable } from 'rxjs';

interface SdApiOption {
    cacheOption?: SdCacheOption;
    timeout?: number;
    autoCache?: boolean;
}
type HttpGetOption = Parameters<HttpClient['get']>[1];
type SdGetOption = HttpGetOption & SdApiOption;
type HttpPostOption = Parameters<HttpClient['post']>[2];
type SdPostOption = HttpPostOption & SdApiOption;
type HttpPutOption = Parameters<HttpClient['put']>[2];
type SdPutOption = HttpPutOption & SdApiOption;
type HttpDeleteOption = Parameters<HttpClient['delete']>[1];
type SdDeleteOption = HttpDeleteOption & SdApiOption;
interface SdApiHandler {
    /** Danh sách host URL mà handler này sẽ xử lý */
    hosts: string[];
    /** Can thiệp request: gắn header, token, transform body... */
    intercept?: (request: HttpRequest<any>) => HttpRequest<any>;
    /** Hook chạy TRƯỚC khi gửi request (dùng để log, tracking...) */
    beforeRemote?: (request: HttpRequest<any>) => void | Promise<void>;
    /** Hook chạy SAU khi nhận response (xử lý lỗi, notify...) */
    afterRemote?: (response: HttpResponse<any> | HttpErrorResponse | Error) => void | Promise<void>;
    /** Transform response body thành kiểu dữ liệu mong muốn */
    mapResponse?: <Tres = any, Tdata = any>(response: Tres) => Tdata;
    /** Timeout tính bằng milliseconds. Mặc định: 30000 (30 giây) */
    timeout?: number;
}
interface ISdApiConfiguration {
    handlers: SdApiHandler[];
}
declare const SD_API_CONFIG: InjectionToken<ISdApiConfiguration>;
declare const SD_API_CONFIGURATION: InjectionToken<ISdApiConfiguration>;

declare class SdApiService {
    #private;
    constructor();
    get http(): HttpClient;
    get: <T = any>(url: string, option?: SdGetOption) => Promise<T>;
    post: <T = any>(url: string, body?: any, option?: SdPostOption) => Promise<T>;
    put: <T = any>(url: string, body?: any, option?: SdPutOption) => Promise<T>;
    delete: <T = any>(url: string, option?: SdDeleteOption) => Promise<T>;
    upload: (url: string, option?: {
        extensions?: string[];
        maxSizeInMb?: number;
    }) => Promise<any>;
    uploadFile: (url: string, file: File) => Promise<any>;
    static ɵfac: i0.ɵɵFactoryDeclaration<SdApiService, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<SdApiService>;
}

declare class SdHttpInterceptor implements HttpInterceptor {
    #private;
    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
    static ɵfac: i0.ɵɵFactoryDeclaration<SdHttpInterceptor, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<SdHttpInterceptor>;
}

declare class SdApiModule {
    static ɵfac: i0.ɵɵFactoryDeclaration<SdApiModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<SdApiModule, never, never, never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<SdApiModule>;
}

export { SD_API_CONFIG, SD_API_CONFIGURATION, SdApiModule, SdApiService, SdHttpInterceptor };
export type { ISdApiConfiguration, SdApiHandler, SdApiOption, SdDeleteOption, SdGetOption, SdPostOption, SdPutOption };
