import type { IConfigCache } from "./ConfigCatCache";
import type { ConfigCatClientOptions, OptionsBase, OptionsForPollingMode } from "./ConfigCatClientOptions";
import { PollingMode } from "./ConfigCatClientOptions";
import type { IConfigFetcher } from "./ConfigFetcher";
import type { IConfigService } from "./ConfigServiceBase";
import { ClientCacheState, RefreshResult } from "./ConfigServiceBase";
import type { IEventEmitter } from "./EventEmitter";
import type { HookEvents, IProvidesHooks } from "./Hooks";
import type { IConfig, SettingValue } from "./ProjectConfig";
import type { IEvaluationDetails, IRolloutEvaluator, SettingTypeOf } from "./RolloutEvaluator";
import type { User } from "./User";
/** ConfigCat SDK client. */
export interface IConfigCatClient extends IProvidesHooks {
    /**
     * Returns the value of a feature flag or setting identified by `key`.
     * @remarks
     * It is important to provide an argument for the `defaultValue` parameter that matches the type of the feature flag or setting you are evaluating.
     * Please refer to {@link https://configcat.com/docs/sdk-reference/js/#setting-type-mapping | this table} for the corresponding types.
     * @param key Key of the feature flag or setting.
     * @param defaultValue In case of failure, this value will be returned. Only the following types are allowed: `string`, `boolean`, `number`, `null` and `undefined`.
     * @param user The User Object to use for evaluating targeting rules and percentage options.
     * @returns A promise that fulfills with the value of the feature flag or setting.
     * @throws {Error} `key` is empty.
     * @throws {TypeError} `defaultValue` is not of an allowed type.
     */
    getValueAsync<T extends SettingValue>(key: string, defaultValue: T, user?: User): Promise<SettingTypeOf<T>>;
    /**
     * Returns the value along with evaluation details of a feature flag or setting identified by `key`.
     * @remarks
     * It is important to provide an argument for the `defaultValue` parameter that matches the type of the feature flag or setting you are evaluating.
     * Please refer to {@link https://configcat.com/docs/sdk-reference/js/#setting-type-mapping | this table} for the corresponding types.
     * @param key Key of the feature flag or setting.
     * @param defaultValue In case of failure, this value will be returned. Only the following types are allowed: `string`, `boolean`, `number`, `null` and `undefined`.
     * @param user The User Object to use for evaluating targeting rules and percentage options.
     * @returns A promise that fulfills with the value along with the details of evaluation of the feature flag or setting.
     * @throws {Error} `key` is empty.
     * @throws {TypeError} `defaultValue` is not of an allowed type.
     */
    getValueDetailsAsync<T extends SettingValue>(key: string, defaultValue: T, user?: User): Promise<IEvaluationDetails<SettingTypeOf<T>>>;
    /**
     * Returns all setting keys.
     * @returns A promise that fulfills with the array of keys.
     */
    getAllKeysAsync(): Promise<string[]>;
    /**
     * Returns the keys and values of all feature flags and settings.
     * @param user The User Object to use for evaluating targeting rules and percentage options.
     * @returns A promise that fulfills with the array of key-value pairs.
     */
    getAllValuesAsync(user?: User): Promise<SettingKeyValue[]>;
    /**
     * Returns the values along with evaluation details of all feature flags and settings.
     * @param user The User Object to use for evaluating targeting rules and percentage options.
     * @returns A promise that fulfills with the array of values along with evaluation details.
     */
    getAllValueDetailsAsync(user?: User): Promise<IEvaluationDetails[]>;
    /** Returns the key of a setting and it's value identified by the given Variation ID (analytics) */
    /**
     * Returns the key of a setting and its value identified by the specified `variationId`.
     * @param variationId Variation ID (analytics).
     * @returns A promise that fulfills with the key-value pair.
     */
    getKeyAndValueAsync(variationId: string): Promise<SettingKeyValue | null>;
    /**
     * Refreshes the locally cached config by fetching the latest version from the remote server.
     * @returns A promise that fulfills with the refresh result.
     */
    forceRefreshAsync(): Promise<RefreshResult>;
    /**
     * Waits for the client initialization.
     * @returns A promise that fulfills with the client's initialization state.
     */
    waitForReady(): Promise<ClientCacheState>;
    /**
     * Captures the current state of the client.
     * The resulting snapshot can be used to synchronously evaluate feature flags and settings based on the captured state.
     */
    snapshot(): IConfigCatClientSnapshot;
    /**
     * Sets the default user.
     * @param defaultUser The default User Object to use for evaluating targeting rules and percentage options.
     */
    setDefaultUser(defaultUser: User): void;
    /**
     * Clears the default user.
     */
    clearDefaultUser(): void;
    /**
     * Returns `true` when the client is configured not to initiate HTTP requests, otherwise `false`.
     */
    readonly isOffline: boolean;
    /**
     * Configures the client to allow HTTP requests.
     */
    setOnline(): void;
    /**
     * Configures the client to not initiate HTTP requests and work using the locally cached config only.
     */
    setOffline(): void;
    /**
     * Releases all resources used by the client.
     */
    dispose(): void;
}
/** Represents the state of `IConfigCatClient` captured at a specific point in time. */
export interface IConfigCatClientSnapshot {
    readonly cacheState: ClientCacheState;
    /** The latest config which has been fetched from the remote server. */
    readonly fetchedConfig: IConfig | null;
    /**
     * Returns the available setting keys.
     * (In case the client is configured to use flag override, this will also include the keys provided by the flag override).
     */
    getAllKeys(): ReadonlyArray<string>;
    /**
     * Returns the value of a feature flag or setting identified by `key` synchronously, based on the snapshot.
     * @remarks
     * It is important to provide an argument for the `defaultValue` parameter that matches the type of the feature flag or setting you are evaluating.
     * Please refer to {@link https://configcat.com/docs/sdk-reference/js/#setting-type-mapping | this table} for the corresponding types.
     * @param key Key of the feature flag or setting.
     * @param defaultValue In case of failure, this value will be returned. Only the following types are allowed: `string`, `boolean`, `number`, `null` and `undefined`.
     * @param user The User Object to use for evaluating targeting rules and percentage options.
     * @returns The cached value of the feature flag or setting.
     * @throws {Error} `key` is empty.
     * @throws {TypeError} `defaultValue` is not of an allowed type.
     */
    getValue<T extends SettingValue>(key: string, defaultValue: T, user?: User): SettingTypeOf<T>;
    /**
   * Returns the value along with evaluation details of a feature flag or setting identified by `key` synchronously, based on the snapshot.
   * @remarks
   * It is important to provide an argument for the `defaultValue` parameter that matches the type of the feature flag or setting you are evaluating.
   * Please refer to {@link https://configcat.com/docs/sdk-reference/js/#setting-type-mapping | this table} for the corresponding types.
   * @param key Key of the feature flag or setting.
   * @param defaultValue In case of failure, this value will be returned. Only the following types are allowed: `string`, `boolean`, `number`, `null` and `undefined`.
   * @param user The User Object to use for evaluating targeting rules and percentage options.
   * @returns The cached value along with the details of evaluation of the feature flag or setting.
   * @throws {Error} `key` is empty.
   * @throws {TypeError} `defaultValue` is not of an allowed type.
   */
    getValueDetails<T extends SettingValue>(key: string, defaultValue: T, user?: User): IEvaluationDetails<SettingTypeOf<T>>;
}
export interface IConfigCatKernel {
    configFetcher: IConfigFetcher;
    sdkType: string;
    sdkVersion: string;
    defaultCacheFactory?: (options: OptionsBase) => IConfigCache;
    eventEmitterFactory?: () => IEventEmitter;
}
export declare class ConfigCatClientCache {
    private readonly instances;
    getOrCreate(options: ConfigCatClientOptions, configCatKernel: IConfigCatKernel): [ConfigCatClient, boolean];
    remove(sdkKey: string, cacheToken: object): boolean;
    clear(): ConfigCatClient[];
}
export declare class ConfigCatClient implements IConfigCatClient {
    private readonly cacheToken?;
    protected configService?: IConfigService;
    protected evaluator: IRolloutEvaluator;
    private readonly options;
    private readonly hooks;
    private defaultUser?;
    private readonly suppressFinalize;
    private static get instanceCache();
    static get<TMode extends PollingMode>(sdkKey: string, pollingMode: TMode, options: OptionsForPollingMode<TMode> | undefined | null, configCatKernel: IConfigCatKernel): IConfigCatClient;
    constructor(options: ConfigCatClientOptions, configCatKernel: IConfigCatKernel, cacheToken?: object | undefined);
    private static finalize;
    private static close;
    dispose(): void;
    static disposeAll(): void;
    getValueAsync<T extends SettingValue>(key: string, defaultValue: T, user?: User): Promise<SettingTypeOf<T>>;
    getValueDetailsAsync<T extends SettingValue>(key: string, defaultValue: T, user?: User): Promise<IEvaluationDetails<SettingTypeOf<T>>>;
    getAllKeysAsync(): Promise<string[]>;
    getAllValuesAsync(user?: User): Promise<SettingKeyValue[]>;
    getAllValueDetailsAsync(user?: User): Promise<IEvaluationDetails[]>;
    getKeyAndValueAsync(variationId: string): Promise<SettingKeyValue | null>;
    forceRefreshAsync(): Promise<RefreshResult>;
    setDefaultUser(defaultUser: User): void;
    clearDefaultUser(): void;
    get isOffline(): boolean;
    setOnline(): void;
    setOffline(): void;
    waitForReady(): Promise<ClientCacheState>;
    snapshot(): IConfigCatClientSnapshot;
    private getSettingsAsync;
    /** @inheritdoc */
    addListener: <TEventName extends keyof HookEvents>(eventName: TEventName, listener: (...args: HookEvents[TEventName]) => void) => this;
    /** @inheritdoc */
    on<TEventName extends keyof HookEvents>(eventName: TEventName, listener: (...args: HookEvents[TEventName]) => void): this;
    /** @inheritdoc */
    once<TEventName extends keyof HookEvents>(eventName: TEventName, listener: (...args: HookEvents[TEventName]) => void): this;
    /** @inheritdoc */
    removeListener<TEventName extends keyof HookEvents>(eventName: TEventName, listener: (...args: HookEvents[TEventName]) => void): this;
    /** @inheritdoc */
    off: <TEventName extends keyof HookEvents>(eventName: TEventName, listener: (...args: HookEvents[TEventName]) => void) => this;
    /** @inheritdoc */
    removeAllListeners(eventName?: keyof HookEvents): this;
    /** @inheritdoc */
    listeners(eventName: keyof HookEvents): Function[];
    /** @inheritdoc */
    listenerCount(eventName: keyof HookEvents): number;
    /** @inheritdoc */
    eventNames(): Array<keyof HookEvents>;
}
/** Setting key-value pair. */
export declare class SettingKeyValue<TValue extends SettingValue = SettingValue> {
    settingKey: string;
    settingValue: TValue;
    constructor(settingKey: string, settingValue: TValue);
}
//# sourceMappingURL=ConfigCatClient.d.ts.map