import { ListActionsResult, ListOutputsResult, Validation } from '@bsv/sdk';
import { TableCertificate, TableCertificateField, TableCertificateX, TableCommission, TableMonitorEvent, TableOutput, TableOutputBasket, TableOutputTag, TableOutputTagMap, TableProvenTx, TableProvenTxReq, TableSettings, TableSyncState, TableTransaction, TableTxLabel, TableTxLabelMap, TableUser } from './schema/tables';
import { Knex } from 'knex';
import { AdminStatsResult, StorageProvider, StorageProviderOptions } from './StorageProvider';
import { DBType } from './StorageReader';
import { AuthId, FindCertificateFieldsArgs, FindCertificatesArgs, FindCommissionsArgs, FindForUserSincePagedArgs, FindMonitorEventsArgs, FindOutputBasketsArgs, FindOutputsArgs, FindOutputTagMapsArgs, FindOutputTagsArgs, FindPartialSincePagedArgs, FindProvenTxReqsArgs, FindProvenTxsArgs, FindSyncStatesArgs, FindTransactionsArgs, FindTxLabelMapsArgs, FindTxLabelsArgs, FindUsersArgs, ProvenOrRawTx, PurgeParams, PurgeResults, TrxToken, WalletStorageProvider } from '../sdk/WalletStorage.interfaces';
import { EntityTimeStamp } from '../sdk/types';
export interface StorageKnexOptions extends StorageProviderOptions {
    /**
     * Knex database interface initialized with valid connection configuration.
     */
    knex: Knex;
}
export declare class StorageKnex extends StorageProvider implements WalletStorageProvider {
    knex: Knex;
    constructor(options: StorageKnexOptions);
    readSettings(): Promise<TableSettings>;
    getProvenOrRawTx(txid: string, trx?: TrxToken): Promise<ProvenOrRawTx>;
    dbTypeSubstring(source: string, fromOffset: number, forLength?: number): string;
    getRawTxOfKnownValidTransaction(txid?: string, offset?: number, length?: number, trx?: TrxToken): Promise<number[] | undefined>;
    getProvenTxsForUserQuery(args: FindForUserSincePagedArgs): Knex.QueryBuilder;
    getProvenTxsForUser(args: FindForUserSincePagedArgs): Promise<TableProvenTx[]>;
    getProvenTxReqsForUserQuery(args: FindForUserSincePagedArgs): Knex.QueryBuilder;
    getProvenTxReqsForUser(args: FindForUserSincePagedArgs): Promise<TableProvenTxReq[]>;
    getTxLabelMapsForUserQuery(args: FindForUserSincePagedArgs): Knex.QueryBuilder;
    getTxLabelMapsForUser(args: FindForUserSincePagedArgs): Promise<TableTxLabelMap[]>;
    getOutputTagMapsForUserQuery(args: FindForUserSincePagedArgs): Knex.QueryBuilder;
    getOutputTagMapsForUser(args: FindForUserSincePagedArgs): Promise<TableOutputTagMap[]>;
    listActions(auth: AuthId, vargs: Validation.ValidListActionsArgs): Promise<ListActionsResult>;
    listOutputs(auth: AuthId, vargs: Validation.ValidListOutputsArgs): Promise<ListOutputsResult>;
    insertProvenTx(tx: TableProvenTx, trx?: TrxToken): Promise<number>;
    insertProvenTxReq(tx: TableProvenTxReq, trx?: TrxToken): Promise<number>;
    insertUser(user: TableUser, trx?: TrxToken): Promise<number>;
    insertCertificateAuth(auth: AuthId, certificate: TableCertificateX): Promise<number>;
    insertCertificate(certificate: TableCertificateX, trx?: TrxToken): Promise<number>;
    insertCertificateField(certificateField: TableCertificateField, trx?: TrxToken): Promise<void>;
    insertOutputBasket(basket: TableOutputBasket, trx?: TrxToken): Promise<number>;
    insertTransaction(tx: TableTransaction, trx?: TrxToken): Promise<number>;
    insertCommission(commission: TableCommission, trx?: TrxToken): Promise<number>;
    insertOutput(output: TableOutput, trx?: TrxToken): Promise<number>;
    insertOutputTag(tag: TableOutputTag, trx?: TrxToken): Promise<number>;
    insertOutputTagMap(tagMap: TableOutputTagMap, trx?: TrxToken): Promise<void>;
    insertTxLabel(label: TableTxLabel, trx?: TrxToken): Promise<number>;
    insertTxLabelMap(labelMap: TableTxLabelMap, trx?: TrxToken): Promise<void>;
    insertMonitorEvent(event: TableMonitorEvent, trx?: TrxToken): Promise<number>;
    insertSyncState(syncState: TableSyncState, trx?: TrxToken): Promise<number>;
    updateCertificateField(certificateId: number, fieldName: string, update: Partial<TableCertificateField>, trx?: TrxToken): Promise<number>;
    updateCertificate(id: number, update: Partial<TableCertificate>, trx?: TrxToken): Promise<number>;
    updateCommission(id: number, update: Partial<TableCommission>, trx?: TrxToken): Promise<number>;
    updateOutputBasket(id: number, update: Partial<TableOutputBasket>, trx?: TrxToken): Promise<number>;
    updateOutput(id: number, update: Partial<TableOutput>, trx?: TrxToken): Promise<number>;
    updateOutputTagMap(outputId: number, tagId: number, update: Partial<TableOutputTagMap>, trx?: TrxToken): Promise<number>;
    updateOutputTag(id: number, update: Partial<TableOutputTag>, trx?: TrxToken): Promise<number>;
    updateProvenTxReq(id: number | number[], update: Partial<TableProvenTxReq>, trx?: TrxToken): Promise<number>;
    updateProvenTx(id: number, update: Partial<TableProvenTx>, trx?: TrxToken): Promise<number>;
    updateSyncState(id: number, update: Partial<TableSyncState>, trx?: TrxToken): Promise<number>;
    updateTransaction(id: number | number[], update: Partial<TableTransaction>, trx?: TrxToken): Promise<number>;
    updateTxLabelMap(transactionId: number, txLabelId: number, update: Partial<TableTxLabelMap>, trx?: TrxToken): Promise<number>;
    updateTxLabel(id: number, update: Partial<TableTxLabel>, trx?: TrxToken): Promise<number>;
    updateUser(id: number, update: Partial<TableUser>, trx?: TrxToken): Promise<number>;
    updateMonitorEvent(id: number, update: Partial<TableMonitorEvent>, trx?: TrxToken): Promise<number>;
    setupQuery<T extends object>(table: string, args: FindPartialSincePagedArgs<T>): Knex.QueryBuilder;
    findCertificateFieldsQuery(args: FindCertificateFieldsArgs): Knex.QueryBuilder;
    findCertificatesQuery(args: FindCertificatesArgs): Knex.QueryBuilder;
    findCommissionsQuery(args: FindCommissionsArgs): Knex.QueryBuilder;
    findOutputBasketsQuery(args: FindOutputBasketsArgs): Knex.QueryBuilder;
    findOutputsQuery(args: FindOutputsArgs, count?: boolean): Knex.QueryBuilder;
    findOutputTagMapsQuery(args: FindOutputTagMapsArgs): Knex.QueryBuilder;
    findOutputTagsQuery(args: FindOutputTagsArgs): Knex.QueryBuilder;
    findProvenTxReqsQuery(args: FindProvenTxReqsArgs): Knex.QueryBuilder;
    findProvenTxsQuery(args: FindProvenTxsArgs): Knex.QueryBuilder;
    findSyncStatesQuery(args: FindSyncStatesArgs): Knex.QueryBuilder;
    findTransactionsQuery(args: FindTransactionsArgs, count?: boolean): Knex.QueryBuilder;
    findTxLabelMapsQuery(args: FindTxLabelMapsArgs): Knex.QueryBuilder;
    findTxLabelsQuery(args: FindTxLabelsArgs): Knex.QueryBuilder;
    findUsersQuery(args: FindUsersArgs): Knex.QueryBuilder;
    findMonitorEventsQuery(args: FindMonitorEventsArgs): Knex.QueryBuilder;
    findCertificatesAuth(auth: AuthId, args: FindCertificatesArgs): Promise<TableCertificateX[]>;
    findOutputBasketsAuth(auth: AuthId, args: FindOutputBasketsArgs): Promise<TableOutputBasket[]>;
    findOutputsAuth(auth: AuthId, args: FindOutputsArgs): Promise<TableOutput[]>;
    findCertificateFields(args: FindCertificateFieldsArgs): Promise<TableCertificateField[]>;
    findCertificates(args: FindCertificatesArgs): Promise<TableCertificateX[]>;
    findCommissions(args: FindCommissionsArgs): Promise<TableCommission[]>;
    findOutputBaskets(args: FindOutputBasketsArgs): Promise<TableOutputBasket[]>;
    findOutputs(args: FindOutputsArgs): Promise<TableOutput[]>;
    findOutputTagMaps(args: FindOutputTagMapsArgs): Promise<TableOutputTagMap[]>;
    findOutputTags(args: FindOutputTagsArgs): Promise<TableOutputTag[]>;
    findProvenTxReqs(args: FindProvenTxReqsArgs): Promise<TableProvenTxReq[]>;
    findProvenTxs(args: FindProvenTxsArgs): Promise<TableProvenTx[]>;
    findSyncStates(args: FindSyncStatesArgs): Promise<TableSyncState[]>;
    findTransactions(args: FindTransactionsArgs): Promise<TableTransaction[]>;
    findTxLabelMaps(args: FindTxLabelMapsArgs): Promise<TableTxLabelMap[]>;
    findTxLabels(args: FindTxLabelsArgs): Promise<TableTxLabel[]>;
    findUsers(args: FindUsersArgs): Promise<TableUser[]>;
    findMonitorEvents(args: FindMonitorEventsArgs): Promise<TableMonitorEvent[]>;
    getCount<T extends object>(q: Knex.QueryBuilder<T, T[]>): Promise<number>;
    countCertificateFields(args: FindCertificateFieldsArgs): Promise<number>;
    countCertificates(args: FindCertificatesArgs): Promise<number>;
    countCommissions(args: FindCommissionsArgs): Promise<number>;
    countOutputBaskets(args: FindOutputBasketsArgs): Promise<number>;
    countOutputs(args: FindOutputsArgs): Promise<number>;
    countOutputTagMaps(args: FindOutputTagMapsArgs): Promise<number>;
    countOutputTags(args: FindOutputTagsArgs): Promise<number>;
    countProvenTxReqs(args: FindProvenTxReqsArgs): Promise<number>;
    countProvenTxs(args: FindProvenTxsArgs): Promise<number>;
    countSyncStates(args: FindSyncStatesArgs): Promise<number>;
    countTransactions(args: FindTransactionsArgs): Promise<number>;
    countTxLabelMaps(args: FindTxLabelMapsArgs): Promise<number>;
    countTxLabels(args: FindTxLabelsArgs): Promise<number>;
    countUsers(args: FindUsersArgs): Promise<number>;
    countMonitorEvents(args: FindMonitorEventsArgs): Promise<number>;
    destroy(): Promise<void>;
    migrate(storageName: string, storageIdentityKey: string): Promise<string>;
    dropAllData(): Promise<void>;
    transaction<T>(scope: (trx: TrxToken) => Promise<T>, trx?: TrxToken): Promise<T>;
    /**
     * Convert the standard optional `TrxToken` parameter into either a direct knex database instance,
     * or a Knex.Transaction as appropriate.
     */
    toDb(trx?: TrxToken): Knex<any, any[]>;
    validateRawTransaction(t: TableTransaction, trx?: TrxToken): Promise<void>;
    _verifiedReadyForDatabaseAccess: boolean;
    /**
     * Make sure database is ready for access:
     *
     * - dateScheme is known
     * - foreign key constraints are enabled
     *
     * @param trx
     */
    verifyReadyForDatabaseAccess(trx?: TrxToken): Promise<DBType>;
    /**
     * Helper to force uniform behavior across database engines.
     * Use to process the update template for entities being updated.
     */
    validatePartialForUpdate<T extends EntityTimeStamp>(update: Partial<T>, dateFields?: string[], booleanFields?: string[]): Partial<T>;
    /**
     * Helper to force uniform behavior across database engines.
     * Use to process new entities being inserted into the database.
     */
    validateEntityForInsert<T extends EntityTimeStamp>(entity: T, trx?: TrxToken, dateFields?: string[], booleanFields?: string[]): Promise<any>;
    getLabelsForTransactionId(transactionId?: number, trx?: TrxToken): Promise<TableTxLabel[]>;
    getTagsForOutputId(outputId: number, trx?: TrxToken): Promise<TableOutputTag[]>;
    purgeData(params: PurgeParams, trx?: TrxToken): Promise<PurgeResults>;
    reviewStatus(args: {
        agedLimit: Date;
        trx?: TrxToken;
    }): Promise<{
        log: string;
    }>;
    /**
     * Counts the outputs for userId in basketId that are spendable: true
     * AND whose transaction status is one of:
     * - completed
     * - unproven
     * - sending (if excludeSending is false)
     */
    countChangeInputs(userId: number, basketId: number, excludeSending: boolean): Promise<number>;
    findOutputsByIds(outputIds: number[], trx?: TrxToken): Promise<Record<number, TableOutput>>;
    findOutputsByOutpoints(userId: number, outpoints: Array<{
        txid: string;
        vout: number;
    }>, trx?: TrxToken): Promise<Record<string, TableOutput>>;
    findOrInsertOutputBasketsBulk(userId: number, names: string[], trx?: TrxToken): Promise<Record<string, TableOutputBasket>>;
    findOrInsertOutputTagsBulk(userId: number, tags: string[], trx?: TrxToken): Promise<Record<string, TableOutputTag>>;
    sumSpendableSatoshisInBasket(userId: number, basketId: number, excludeSending: boolean, trx?: TrxToken): Promise<number>;
    /**
     *  Finds closest matching available change output to use as input for new transaction.
     *
     * Transactionally allocate the output such that
     */
    allocateChangeInput(userId: number, basketId: number, targetSatoshis: number, exactSatoshis: number | undefined, excludeSending: boolean, transactionId: number): Promise<TableOutput | undefined>;
    /**
     * Helper to force uniform behavior across database engines.
     * Use to process all individual records with time stamps retreived from database.
     */
    validateEntity<T extends EntityTimeStamp>(entity: T, dateFields?: string[], booleanFields?: string[]): T;
    /**
     * Helper to force uniform behavior across database engines.
     * Use to process all arrays of records with time stamps retreived from database.
     * @returns input `entities` array with contained values validated.
     */
    validateEntities<T extends EntityTimeStamp>(entities: T[], dateFields?: string[], booleanFields?: string[]): T[];
    adminStats(adminIdentityKey: string): Promise<AdminStatsResult>;
}
//# sourceMappingURL=StorageKnex.d.ts.map