import * as sqlite from 'sqlite';
import * as sqlite3 from 'sqlite3';
import { SqlManager } from 'rg-sqlite-helper';
import { Response, Request, RequestHandler } from 'express';

interface FileObject{

	name:string
	original_name:string
	content_type:string
	timestamp:string
	access:'public'| 'private'
	uploader_id:string,
	meta:string,
	sizeBytes:number,
/*	data:Buffer*/

}




interface initOptions {
	databasePath:string
	throwIfDatabaseNotExists?:boolean
}

 interface ExtraPutOptions{
	uploaderId?:string,
	meta?:string,
	maxSizeMB?:number
}

interface WebpCompressOptions {
    preset?: string;
    quality?: string;
    lossless?: string;
    crop?: {
        x: string;
        y: string;
        width: string;
        height: string;
    };
    resize?: {
        width: string;
        height: string;
    };
    metadata?: string | string[];
    filter?: string;
}

/**
 * This file was generated by kysely-codegen.
 * Please do not edit it manually.
 */

interface FileData {
  data: Buffer;
  file_name: string;
}

interface Files {
  access: string;
  content_type: string;
  meta: string | null;
  name: string;
  original_name: string;
  sizeBytes: number;
  timestamp: number;
  uploader_id: string | null;
}

interface FileManagerDatabaseType {
  file_data: FileData;
  files: Files;
}

type GetObjectInfo = Pick<FileObject, 'content_type' | 'original_name' | 'access' | 'sizeBytes' | 'name'>;
declare class SqliteFileManager {
    private _connection;
    private readonly _initOptions;
    private loadedBlobIoExtension;
    private constructor();
    static init(options: initOptions): SqliteFileManager;
    vacuum(): Promise<void>;
    close(): Promise<void>;
    getConnection(): Promise<SqlManager>;
    private getFileRowId;
    private getRange;
    private setHeaders;
    sendFile(file: GetObjectInfo, res: Response, req: Request, next: (err?: Error | string) => void): Promise<void>;
    createExpressMiddlewareForPublicFiles: RequestHandler;
    private getContentTypeFromName;
    getObject(name: string): Promise<{
        name: string;
        sizeBytes: number;
        content_type: string;
        original_name: string;
        access: "public" | "private";
    } | null>;
    getObjectEx(name: string): Promise<FileObject | null>;
    getObjectExByUserid(uploaderId: string): Promise<Array<FileObject>>;
    removeObject(name: string): Promise<sqlite.ISqlite.RunResult<sqlite3.Statement>>;
    private mergeExtraOptions;
    putImageCompressFromStream(name: string, webStream: ReadableStream<Uint8Array> | NodeJS.ReadableStream, access: 'public' | 'private', opts?: ExtraPutOptions | undefined, compressOpts?: WebpCompressOptions | undefined, downscale?: boolean): Promise<string>;
    putImageCompressedFromFile(name: string, tempFilePath: string, access: 'public' | 'private', opts?: ExtraPutOptions | undefined, compressOpts?: WebpCompressOptions | undefined, downscale?: boolean): Promise<string>;
    putImageCompressedFromBuffer(name: string, data: Buffer, access: 'public' | 'private', opts?: ExtraPutOptions | undefined, compressOpts?: WebpCompressOptions | undefined, downscale?: boolean): Promise<string>;
    putObjectV2(name: string, tempFilePath: string, access: 'public' | 'private', opts?: ExtraPutOptions): Promise<string>;
    private _validateAndInsertFileV2;
    /**
     * @deprecated dont use
     */
    putObject(name: string, data: ArrayBuffer, access: 'public' | 'private', opts?: ExtraPutOptions): Promise<string>;
    private _validateAndInsertBuffer;
    listObjects(): Promise<Pick<FileObject, "content_type" | "original_name" | "access" | "sizeBytes" | "name" | "timestamp" | "uploader_id">[]>;
}

export { type FileManagerDatabaseType, SqliteFileManager };
