/**
 * @description upload interface
 * @author wangfupeng
 */
import type { IDomEditor } from '../editor/interface';
export type IUploadHeaders = Record<string, string | number>;
export interface IUploadResultFile {
    name: string;
    type?: string;
    size?: number;
    [key: string]: any;
}
export interface IUploadFile {
    name: string;
    type: string;
    size: number;
    data: Blob | File;
    source?: string;
}
export interface IUploader {
    addFiles: (files: IUploadFile[]) => void;
    upload: () => Promise<unknown>;
    destroy?: () => void;
}
type FilesType = Record<string, any>;
type InsertFn = (src: string, poster?: string, alt?: string, href?: string) => void | Promise<void>;
export interface IUploadAdapterContext {
    config: IUploadConfig;
    editor?: IDomEditor;
}
export type IUploadAdapter = (context: IUploadAdapterContext) => IUploader;
interface IBaseUploadConfig {
    fieldName?: string;
    maxFileSize?: number;
    maxNumberOfFiles?: number;
    meta?: Record<string, unknown>;
    metaWithUrl: boolean;
    headers?: IUploadHeaders | ((file: IUploadResultFile) => IUploadHeaders) | undefined;
    withCredentials?: boolean;
    timeout?: number;
    onBeforeUpload?: (files: FilesType) => boolean | FilesType;
    onSuccess: (file: IUploadResultFile, response: any) => void;
    onProgress?: (progress: number) => void;
    onFailed: (file: IUploadResultFile, response: any) => void;
    onError: (file: IUploadResultFile, error: any, res: any) => void;
    allowedFileTypes?: string[];
    customInsert?: (res: any, insertFn: InsertFn) => void;
    customUpload?: (files: File, insertFn: InsertFn, editor: IDomEditor) => void;
    customBrowseAndUpload?: (insertFn: InsertFn) => void;
    uploadAdapter?: IUploadAdapter;
    uppyConfig?: Record<string, any>;
    xhrConfig?: Record<string, any>;
}
interface IUploadConfigWithCustomUpload extends IBaseUploadConfig {
    server?: string;
    customUpload: (files: File, insertFn: InsertFn, editor: IDomEditor) => void;
}
interface IUploadConfigWithUploadAdapter extends IBaseUploadConfig {
    server?: string;
    uploadAdapter: IUploadAdapter;
    customUpload?: (files: File, insertFn: InsertFn, editor: IDomEditor) => void;
}
interface IUploadConfigWithoutCustomUpload extends IBaseUploadConfig {
    server: string;
    customUpload?: never;
    uploadAdapter?: never;
}
/**
 * 配置参考 https://uppy.io/docs/uppy/
 */
export type IUploadConfig = IUploadConfigWithCustomUpload | IUploadConfigWithUploadAdapter | IUploadConfigWithoutCustomUpload;
export {};
