import { AggregateOptions, AggregationCursor, BulkWriteOptions, BulkWriteResult, ChangeStream, ChangeStreamOptions, Collection, CollectionInfo, CommandOperationOptions, CountDocumentsOptions, CreateCollectionOptions, CreateIndexesOptions, DeleteOptions, DeleteResult, FindCursor, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, FindOptions, IndexDescription, IndexDescriptionCompact, IndexInformationOptions, InsertOneOptions, ListIndexesCursor, ListIndexesOptions, RenameOptions, ReplaceOptions, UpdateOptions, UpdateResult } from 'mongodb';
import { CollectionDocument, Document } from '../models/collection-document.model';
import { LookupTables } from '../models/report-builder.model';
import { UserModel } from '../models/user.model';
type MongoManagerFindOptions = FindOptions;
export declare interface MongoManagerFilterParamaterOperators<P> {
    $eq?: P;
    $gt?: P;
    $gte?: P;
    $in?: [P] extends [Array<any>] ? P : P[];
    $lt?: P;
    $lte?: P;
    $ne?: P;
    $nin?: [P] extends [Array<any>] ? P : P[];
    $not?: P extends string ? MongoManagerFilterParamaterOperators<P> | RegExpConstructor : MongoManagerFilterParamaterOperators<P>;
    $exists?: boolean;
    $expr?: any[];
    $regex?: P extends string ? RegExpConstructor | string : never;
    $options?: P extends string ? string : never;
    $geoIntersects?: {
        $geometry: Document;
    };
    $geoWithin?: Document;
    $near?: Document;
    $nearSphere?: Document;
    $maxDistance?: number;
    $all?: any[];
    $elemMatch?: Document;
    $size?: P extends any[] ? number : never;
}
export declare interface MongoManagerFilterOperators<T> extends Document {
    $and?: MongoManagerFilter<T>[] | MongoManagerFilterOperators<T>;
    $nor?: MongoManagerFilter<T>[] | MongoManagerFilterOperators<T>;
    $or?: MongoManagerFilter<T>[] | MongoManagerFilterOperators<T>;
    $text?: {
        $search: string;
        $language?: string;
        $caseSensitive?: boolean;
        $diacriticSensitive?: boolean;
    };
    $where?: string | ((this: T) => boolean);
    $comment?: string | Document;
}
export declare type MongoManagerFilter<T> = {
    [P in keyof T]?: T[P] | MongoManagerFilterParamaterOperators<T[P]>;
};
export declare type MongoManagerUnsetFilter<T> = {
    [P in keyof T]?: number | boolean;
};
export declare type MongoManagerIncFilter<T> = {
    [P in keyof T]?: number;
};
export declare type MongoManagerRenameFilter<T> = {
    [P in keyof T]?: string;
};
export declare type MongoManagerArrayFilter<T> = {
    [P in keyof T]?: any;
};
export declare type MongoManagerCurrentDateFilter<T> = {
    [P in keyof T]?: true | {
        $type: 'date' | 'timestamp';
    };
};
export declare type MongoManagerUpdateFilter<T> = {
    $set?: MongoManagerFilter<T> | Document;
    $unset?: MongoManagerUnsetFilter<T> | Document;
    $inc?: MongoManagerIncFilter<T> | Document;
    $setOnInsert?: MongoManagerFilter<T> | Document;
    $push?: MongoManagerArrayFilter<T> | Document;
    $pull?: MongoManagerArrayFilter<T> | Document;
    $addToSet?: MongoManagerArrayFilter<T> | Document;
    $min?: MongoManagerIncFilter<T> | Document;
    $max?: MongoManagerIncFilter<T> | Document;
    $currentDate?: MongoManagerCurrentDateFilter<T> | Document;
    $mul?: MongoManagerIncFilter<T> | Document;
    $rename?: MongoManagerRenameFilter<T>;
};
export declare class MongoManager {
    private _collections;
    private _nodeCache;
    private _cacheMap;
    private _operationInProgress;
    private _heapSize;
    private _heapLimit;
    private _serverCollections;
    private _isWorkersEnabled;
    private _isWorkerInstance;
    private _watchedDatabases;
    private _mainDatabaseName;
    private _changeStream;
    private _changeStreamRestartTimeout;
    constructor();
    static create(): Promise<MongoManager>;
    private initialize;
    private resolveWatchedDatabases;
    getWatchedDatabases(): string[];
    oneTimeTransaction<T>(fn: () => Promise<T>): Promise<T>;
    getSession(): any;
    runWithoutSession<T>(fn: () => Promise<T> | T): Promise<T>;
    private setCacheLimit;
    getServerCollections(): (CollectionInfo | Pick<CollectionInfo, "type" | "name">)[];
    registerCollection(collection: MongoManagerCollection<CollectionDocument>): Promise<void>;
    createCollection(collection: MongoManagerCollection<CollectionDocument>): Promise<void>;
    collections(): MongoManagerCollection<CollectionDocument>[];
    collection(collectionName: string): MongoManagerCollection<CollectionDocument> | MongoManagerUserCollection<CollectionDocument>;
    private delay;
    private hasMongoErrorLabel;
    private shouldRetryWriteConflict;
    private shouldRetryTransactionError;
    private shouldRetryWaitQueueTimeout;
    private shouldRetryConnectionError;
    private retryRead;
    find<T extends CollectionDocument>(collectionName: string, filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: MongoManagerFindOptions): Promise<T[]>;
    private executeFind;
    findOne<T extends CollectionDocument>(collectionName: string, filter?: MongoManagerFilter<T> | MongoManagerFilterOperators<T>, options?: MongoManagerFindOptions): Promise<T>;
    private executeFindOne;
    aggregate<T extends CollectionDocument>(collectionName: string, pipeline: any[], options?: AggregateOptions): Promise<any[]>;
    private executeAggregate;
    countDocuments<T extends CollectionDocument>(collectionName: string, filter?: MongoManagerFilter<T> | MongoManagerFilterOperators<T>, options?: CountDocumentsOptions): Promise<number>;
    private executeCountDocuments;
    private generateCacheKey;
    private getFromCache;
    private addToCache;
    invalidateQueryCache(collection: string, bypassLocalOplog?: boolean): void;
    clearQueryCache(reason?: string): void;
    handleMongoReconnect(reason: string): Promise<void>;
    private setupChangeStream;
    private teardownChangeStream;
    private handleChangeStreamFailure;
    private scheduleChangeStreamRestart;
}
export declare class MongoManagerModel<T extends CollectionDocument> {
    collection_main: MongoManagerCollection<T> | MongoManagerUserCollection<T>;
    collection_version: MongoManagerCollection<T> | MongoManagerUserCollection<T>;
    constructor();
    static create<T>(options: MongoManagerCollectionOptions): MongoManagerModel<T>;
    private initialize;
}
export interface MongoManagerCollectionOptions {
    collectionName: string;
    schema: object;
    useVersionCollection: boolean;
    useReportBuilder: boolean;
    reportBuilderLookupTables: LookupTables[];
    timestamps: boolean;
    createLogs: boolean;
    checkSchema: boolean;
    collectionOptions: CreateCollectionOptions;
    skipCache?: boolean;
    bypassSession?: boolean;
    searchFields?: string[];
}
export declare class MongoManagerCollection<T extends CollectionDocument> {
    collectionName: string;
    checkSchema: boolean;
    simplschema: any;
    rbSchema: any;
    timestamps: boolean;
    useVersions: boolean;
    versionCollection: string;
    createLogs: boolean;
    useRB: boolean;
    collectionOptions: CreateCollectionOptions;
    skipCache: boolean;
    bypassSession: boolean;
    constructor();
    static create(options: MongoManagerCollectionOptions): MongoManagerCollection<CollectionDocument>;
    initialize(options: MongoManagerCollectionOptions): void;
    extractIndexNameFromError(errorMessage: any): any;
    private shouldRetryWriteConflict;
    private shouldRetryWaitQueueTimeout;
    private shouldRetryConnectionError;
    private delay;
    private retryWrite;
    private retryRead;
    aggregate(pipeline: object[], options?: AggregateOptions, skipCache?: boolean, bypassSession?: boolean): Promise<any[]>;
    aggregateCount(pipeline: object[], options?: AggregateOptions, bypassSession?: boolean): Promise<number>;
    aggregateCursor(pipeline: object[], options?: AggregateOptions, bypassSession?: boolean): AggregationCursor;
    aggregateStream(pipeline: object[], options?: AggregateOptions, streamOptions?: any, bypassSession?: boolean): import("stream").Readable & AsyncIterable<import("bson").Document>;
    bulkWrite(operations: any[], options?: BulkWriteOptions, bypassCheckSchema?: boolean, bypassLogs?: boolean, bypassVersions?: boolean, bypassSession?: boolean): Promise<BulkWriteResult>;
    countDocuments(filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: CountDocumentsOptions, skipCache?: boolean): Promise<number>;
    create(f_docs: T | T[], options?: InsertOneOptions | BulkWriteOptions): Promise<T | T[]>;
    createIndex(fieldOrSpec: any, options?: CreateIndexesOptions): Promise<string>;
    createIndexes(indexSpecs: IndexDescription[], options?: CreateIndexesOptions): Promise<string[]>;
    deleteMany(filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: DeleteOptions, bypassLogs?: boolean, bypassSession?: boolean): Promise<DeleteResult>;
    deleteOne(filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: FindOneAndDeleteOptions, bypassLogs?: boolean, bypassSession?: boolean): Promise<DeleteResult>;
    distinct(key: string, filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: CommandOperationOptions, bypassSession?: boolean): Promise<T[]>;
    drop(options?: CommandOperationOptions, bypassSession?: boolean): Promise<boolean>;
    dropIndex(indexName: string, options?: CommandOperationOptions, bypassSession?: boolean): Promise<Document>;
    dropIndexes(options?: CommandOperationOptions, bypassSession?: boolean): Promise<boolean>;
    find(filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: MongoManagerFindOptions, skipCache?: boolean, bypassSession?: boolean): Promise<T[]>;
    findById(id: string, options?: MongoManagerFindOptions, skipCache?: boolean, bypassSession?: boolean): Promise<T>;
    findCount(filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: MongoManagerFindOptions, bypassSession?: boolean): Promise<Number>;
    findCursor(filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: MongoManagerFindOptions, bypassSession?: boolean): FindCursor;
    findStream(filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: MongoManagerFindOptions, streamOptions?: any, bypassSession?: boolean): import("stream").Readable & AsyncIterable<import("mongodb").WithId<T>>;
    findOne(filter?: MongoManagerFilter<T> | MongoManagerFilterOperators<T>, options?: MongoManagerFindOptions, skipCache?: boolean, bypassSession?: boolean): Promise<T>;
    findOneAndDelete(filter?: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, options?: FindOneAndDeleteOptions, bypassLogs?: boolean, bypassSession?: boolean): Promise<T>;
    findOneAndReplace(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, replacement: T, options?: FindOneAndReplaceOptions, bypassLogs?: boolean, bypassCheckSchema?: boolean, bypassSession?: boolean): Promise<T>;
    findOneAndUpdate(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, update: MongoManagerUpdateFilter<T>, options?: FindOneAndUpdateOptions, bypassLogs?: boolean, bypassCheckSchema?: boolean, bypassSession?: boolean): Promise<T>;
    indexes(options: IndexInformationOptions): Promise<IndexDescriptionCompact | IndexDescriptionCompact[]>;
    indexExists(indexes: string | string[], options?: IndexInformationOptions): Promise<boolean>;
    insertMany(docs: T[], options?: BulkWriteOptions, bypassLogs?: boolean, bypassCheckSchema?: boolean, bypassMonitor?: boolean, bypassSession?: boolean): Promise<T[]>;
    insertOne(doc: T, options?: InsertOneOptions, bypassLogs?: boolean, bypassCheckSchema?: boolean, bypassSession?: boolean): Promise<T>;
    listIndexes(options?: ListIndexesOptions, bypassSession?: boolean): ListIndexesCursor;
    rename(newName: string, options?: RenameOptions, bypassSession?: boolean): Promise<Collection<Document>>;
    replaceOne(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, replacement: T, options?: ReplaceOptions, bypassLogs?: boolean, bypassCheckSchema?: boolean, doc?: T, bypassSession?: boolean): Promise<UpdateResult>;
    updateMany(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, update: MongoManagerUpdateFilter<T>, options?: UpdateOptions, bypassLogs?: boolean, bypassCheckSchema?: boolean, bypassVersions?: boolean, bypassSession?: boolean): Promise<UpdateResult>;
    updateOne(filter: MongoManagerFilter<T> & MongoManagerFilterOperators<T>, update: MongoManagerUpdateFilter<T>, options?: UpdateOptions, bypassLogs?: boolean, bypassCheckSchema?: boolean, bypassSession?: boolean): Promise<UpdateResult>;
    watchCollection(pipeline?: any[], options?: ChangeStreamOptions, bypassSession?: boolean): ChangeStream<T>;
}
export declare class MongoManagerUserCollection<T extends CollectionDocument> extends MongoManagerCollection<T> {
    static create(options: MongoManagerCollectionOptions): MongoManagerUserCollection<CollectionDocument>;
    authenticate(user: UserModel, password: string): Promise<{
        data: UserModel;
        error: string;
    }>;
    serializeUser(): (user: any, cb: any) => void;
    deserializeUser(): (username: any) => Promise<UserModel>;
    setPassword(user: UserModel, password: string): Promise<UpdateResult<import("bson").Document>>;
    changePassword(user: any, oldPassword: any, newPassword: any): Promise<UpdateResult<import("bson").Document>>;
    register(user: any, password: any): Promise<any>;
    resetAttempts(user: UserModel): Promise<UpdateResult<import("bson").Document>>;
}
export {};
