/*
 * Microsoft Application Insights idsync plugin, 3.4.3
 * Copyright (c) Microsoft and contributors. All rights reserved.
 *
 * Microsoft Application Insights Team
 * https://github.com/microsoft/ApplicationInsights-JS#readme
 *
 * ---------------------------------------------------------------------------
 * This is a single combined (rollup) declaration file for the package,
 * if you require a namespace wrapped version it is also available.
 * - Namespaced version: types/applicationinsights-cfgsync-js.namespaced.d.ts
 * ---------------------------------------------------------------------------
 */

import { BaseTelemetryPlugin } from '@microsoft/applicationinsights-core-js';
import { IAppInsightsCore } from '@microsoft/applicationinsights-core-js';
import { IConfig } from '@microsoft/applicationinsights-core-js';
import { IConfiguration } from '@microsoft/applicationinsights-core-js';
import { IPlugin } from '@microsoft/applicationinsights-core-js';
import { IProcessTelemetryContext } from '@microsoft/applicationinsights-core-js';
import { ITelemetryItem } from '@microsoft/applicationinsights-core-js';
import { ITelemetryPluginChain } from '@microsoft/applicationinsights-core-js';

export declare class CfgSyncPlugin extends BaseTelemetryPlugin implements ICfgSyncPlugin {
    priority: number;
    identifier: string;
    constructor();
    initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
    /**
     * Get current configs of current instance.
     * @param config - current configs
     */
    getCfg(): IConfiguration & IConfig;
    /**
     * Manually set configs of current instance.
     * @param config - new configs
     */
    setCfg(config?: IConfiguration & IConfig): boolean;
    /**
     * Manually broadcast configs of current instance to all other instances.
     * @param customDetails - additional details should also be sent out to other instances
     */
    sync(customDetails?: any): boolean;
    /**
     * Manually update event name.
     * If current instance is the main instance, then following config changes will be sent out under this new event name.
     * If current instance is listener instances, it will listen to event details under this new name.
     * @param eventName - new event name
     */
    updateEventListenerName(eventName?: string): boolean;
    /**
     * Pause the sending/receiving of events
     */
    pause(): void;
    /**
     * Resume the sending/receiving of events
     */
    resume(): void;
    processTelemetry(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
}

export declare interface ICfgSyncConfig {
    /**
     * Identifies whether instance should receive or broadcast config changes
     * @default Broadcast
     */
    syncMode?: ICfgSyncMode;
    /**
     * Event name for sending or listening to configuration change details
     * @default ai_cfgsync
     */
    customEvtName?: string;
    /**
     * CDN endpoint for fetching configuration. If cfgUrl is defined, instance will NOT listen to core configuration changes.
     * @default null
     */
    cfgUrl?: string;
    /**
     * Determines if fetching the CDN endpoint should be blocked or not.
     * @default false
     */
    blkCdnCfg?: boolean;
    /**
     *  Overrides callback function to handle event details when changes are received via event listener.
     * @default null
     */
    onCfgChangeReceive?: (event?: ICfgSyncEvent) => void;
    /**
     * Overrides sync() function to broadcast changes.
     * @default null
     */
    overrideSyncFn?: (config?: IConfiguration & IConfig, customDetails?: any) => boolean;
    /**
     * Overrides fetch function to get config from cfgUrl when cfgUrl is defined.
     * @default null
     */
    overrideFetchFn?: SendGetFunction;
    /**
     * When current instance is set with syncMode: `Receive`, config fields under nonOverrideConfigs will NOT be changed by any config details sent out from other instances.
     * NOTE: this config will be ONLY applied during initialization, so it won't be changed dynamically
     * @default \{instrumentationKey:true,connectionString:true,endpointUrl:true\}
     */
    nonOverrideConfigs?: NonOverrideCfg;
    /**
     * Identifies the time interval (in milliseconds) for fetching config details from cfgUrl when cfgUrl is defined.
     * Default to 30 mins, 30*60*1000ms.
     * If set to 0, the fetch operation will only be called once during initialization.
     * @default 30mins (30*60*1000ms)
     */
    scheduleFetchTimeout?: number;
    /**
     * An internal flag to determine if sending requests with the internal endpoints as dependency requests.
     * @internal
     * @default false
     * @since 3.3.6
     */
    enableAjax?: boolean;
}

export declare interface ICfgSyncEvent {
    /**
     * Identifies config changes are expected to send out to other instances.
     */
    cfg?: IConfiguration & IConfig;
    /**
     * Identifies additional details that are expected to send out with config changes.
     */
    customDetails?: any;
}

export declare const enum ICfgSyncMode {
    /**
     * Instance will NOT receive config changes or broadcast changes
     */
    None = 0,
    /**
     * Instance will only broadcast config changes but NOT receive changes
     */
    Broadcast = 1,
    /**
     * Instance will only receive config changes but NOT broadcast changes
     */
    Receive = 2
}

export declare interface ICfgSyncPlugin {
    /**
     * Get current configs of current instance.
     * @param config - current configs
     */
    getCfg(): IConfiguration & IConfig;
    /**
     * Manually set configs of current instance.
     * @param config - new configs
     */
    setCfg(config?: IConfiguration & IConfig): boolean;
    /**
     * Manually broadcast configs of current instance to all other instances.
     * @param customDetails - additional details should also be sent out to other instances
     */
    sync(customDetails?: any): boolean;
    /**
     * Manually update event name.
     * If current instance is the main instance, then following config changes will be sent out under this new event name.
     * If current instance is listener instances, it will listen to event details under this new name.
     * @param eventName - new event name
     */
    updateEventListenerName(eventName?: string): boolean;
    /**
     * Pause the sending/receiving of events
     */
    pause(): void;
    /**
     * Resume the sending/receiving of events
     */
    resume(): void;
}

export declare type NonOverrideCfg<T = IConfiguration & IConfig> = {
    [key in keyof T]?: boolean | NonOverrideCfg<T[key]> | undefined;
};

export declare type OnCompleteCallback = (status: number, response?: string, isAutoSync?: boolean) => void;

export declare type SendGetFunction = (url: string, oncomplete: OnCompleteCallback, isAutoSync?: boolean) => void;

export { }
