import { FieldPath, WhereFilterOp, OrderByDirection, DocumentSnapshot, CollectionReference, DocumentData, Query, QuerySnapshot, DocumentReference, SetOptions, Transaction, WriteBatch, FieldValue, Settings } from '@firebase/firestore-types';

type QueryWhere = [fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown];
type QueryOrderBy = [fieldPath: string | FieldPath, directionStr?: OrderByDirection];
type QueryLeftJoin = [idField: string, collection: string, alias: string];
type QueryCursor = [snapshot: DocumentSnapshot<unknown>] | unknown[];
declare class QueryBuilder {
    private _where;
    private _orderBy;
    private _leftJoins;
    private _limit?;
    private _limitToLast?;
    private _startAt?;
    private _startAfter?;
    private _endAt?;
    private _endBefore?;
    get joins(): QueryLeftJoin[];
    where(...where: QueryWhere): this;
    orderBy(...orderBy: QueryOrderBy): this;
    leftJoin(...leftJoin: QueryLeftJoin): void;
    limit(limit: number): this;
    limitToLast(limitToLast: number): this;
    startAt(...startAt: QueryCursor): this;
    startAfter(...startAfter: QueryCursor): this;
    endAt(...endAt: QueryCursor): this;
    endBefore(...endBefore: QueryCursor): this;
    exec(ref: CollectionReference<DocumentData> | any, queryOps?: {
        [key: string]: any;
    }): Query<DocumentData> | any;
    private execQueryForCloud;
}

declare abstract class AbstractFirestoreApi {
    BATCH_MAX_WRITES: number;
    abstract collection<T = any>(path: string, qb?: QueryBuilder, maxAge?: number): Promise<T[]>;
    abstract collectionGroup<T = any>(collectionId: string, qb?: QueryBuilder, maxAge?: number): Promise<T[]>;
    abstract collectionSnapshot(path: string, qb?: QueryBuilder): Promise<QuerySnapshot<DocumentData>>;
    abstract doc<T = any>(path: string, maxAge?: number): Promise<T>;
    abstract docRef(docPath: string): DocumentReference<DocumentData>;
    abstract upsert(collection: string, data: {
        [key: string]: any;
    }, opts?: SetOptions): Promise<string>;
    abstract update(docPath: string, data: {
        [key: string]: any;
    }): Promise<void>;
    abstract delete(docPath: string): Promise<void>;
    abstract bulkUpsert(collection: string, data: DocumentData[] | {
        data: DocumentData;
        qb?: QueryBuilder;
    }, opts?: SetOptions): Promise<string[]>;
    abstract bulkDelete(collection: string, qb?: QueryBuilder): Promise<string[]>;
    abstract runTransaction(updateFunction: (transaction: Transaction) => Promise<unknown>): Promise<unknown>;
    abstract get batch(): WriteBatch;
    abstract get serverTimestamp(): FieldValue;
    abstract increment(n?: number): FieldValue;
    abstract createId(collection?: string): string;
    getValueFromSnapshot<T = any>(snapshot: DocumentSnapshot): T;
}

declare class FirestoreCloudService extends AbstractFirestoreApi {
    private db;
    private admin;
    private static instance;
    static getInstance(admin: any, settings?: Settings): FirestoreCloudService;
    initialize(admin: any, settings: Settings): void;
    collection<T = any>(collection: string, qb?: QueryBuilder): Promise<T[]>;
    collectionGroup<T = any>(collectionId: string, qb?: QueryBuilder): Promise<T[]>;
    doc<T = any>(path: string): Promise<T>;
    upsert(collection: string, data: {
        [key: string]: any;
    }, opts?: SetOptions): Promise<any>;
    update(path: string, data: {
        [key: string]: any;
    }): Promise<void>;
    delete(path: string): Promise<void>;
    /**
     * Bulk update data
     */
    bulkUpsert(path: string, data: DocumentData[] | {
        data: DocumentData;
        qb?: QueryBuilder;
    }, opts?: SetOptions): Promise<string[]>;
    /**
     * Bulk delete data
     */
    bulkDelete(collection: string, qb?: QueryBuilder, maxSize?: number): Promise<any[]>;
    get batch(): WriteBatch;
    get serverTimestamp(): any;
    increment(n?: number): any;
    /**
     * Returns a generated Firestore Document Id.
     */
    createId(colPath?: string): string;
    runTransaction(updateFunction: (transaction: Transaction) => Promise<unknown>): Promise<unknown>;
    recursiveDelete(ref: CollectionReference<unknown> | DocumentReference<unknown>, bulkWriter?: any): any;
    /**
     * Create a Firestore Timestamp
     *
     * @param date
     */
    createTimestamp(date?: Date): any;
    collectionSnapshot(path: string, qb?: QueryBuilder): Promise<QuerySnapshot>;
    collectionGroupSnapshot(collectionId: string, qb?: QueryBuilder): Promise<QuerySnapshot>;
    docRef(path: string): DocumentReference<DocumentData>;
}

declare const arrayToChunks: (list: any[], size: number) => any[][];

export { AbstractFirestoreApi, FirestoreCloudService, QueryBuilder, arrayToChunks };
