import { QueryRunner } from './TypeDef.internal.40.js';

/**
 * Options passed to QueryResultCache class.
 */
interface QueryResultCacheOptions {
    /**
     * Cache identifier set by user.
     * Can be empty.
     */
    identifier?: string;
    /**
     * Time, when cache was created.
     */
    time?: number;
    /**
     * Duration in milliseconds during which results will be returned from cache.
     */
    duration: number;
    /**
     * Cached query.
     */
    query?: string;
    /**
     * Query result that will be cached.
     */
    result?: any;
}

/**
 * Implementations of this interface provide different strategies to cache query builder results.
 */
interface QueryResultCache {
    /**
     * Creates a connection with given cache provider.
     */
    connect(): Promise<void>;
    /**
     * Closes a connection with given cache provider.
     */
    disconnect(): Promise<void>;
    /**
     * Perform operations during schema synchronization.
     */
    synchronize(queryRunner?: QueryRunner): Promise<void>;
    /**
     * Get data from cache.
     * Returns cache result if found.
     * Returns undefined if result is not cached.
     */
    getFromCache(options: QueryResultCacheOptions, queryRunner?: QueryRunner): Promise<QueryResultCacheOptions | undefined>;
    /**
     * Stores given query result in the cache.
     */
    storeInCache(options: QueryResultCacheOptions, savedCache: QueryResultCacheOptions | undefined, queryRunner?: QueryRunner): Promise<void>;
    /**
     * Checks if cache is expired or not.
     */
    isExpired(savedCache: QueryResultCacheOptions): boolean;
    /**
     * Clears everything stored in the cache.
     */
    clear(queryRunner?: QueryRunner): Promise<void>;
    /**
     * Removes all cached results by given identifiers from cache.
     */
    remove(identifiers: string[], queryRunner?: QueryRunner): Promise<void>;
}

export type { QueryResultCache, QueryResultCacheOptions };
