import type OpenFin from '@openfin/core';

export declare type BaseConnectionOptions = {
    /**
     * The URL of the Web Interop broker to connect to. Can be inherited from a parent browsing context if using an <of-view>
     */
    brokerUrl: string;
    /**
     * Tears down and cancels the connection attempt if it is not complete within the specified timeout (in ms).
     */
    timeout?: number;
    /**
     * Interop options to use to generate an interop client in `fin.me.interop`
     */
    interopConfig?: Partial<OpenFin.InteropConfig>;
};

/**
 * ## connect(connectionConfig: ConnectionConfig)
 * Establishes a connection to an OpenFin Web Interop Broker, returning a fin object that supports a subset of APIS.
 *
 * ### Supported APIs
 *
 * * fin.InterApplicationBus.Channels
 * * fin.Interop
 * * fin.me.identity
 *
 * @param connectionConfig Config used to initialise the connection
 * @returns Fin api object
 * @throws If the connection to the broker fails.
 * @throws If the connection elapses the configured timeout
 * @throws If the provided {@link InheritModeConnectConfig.validateOptions} returns false
 * @throws If connection inheritance is enabled but the current browsing context is not rendered in an <of-view> element and no {@link ConnectionConfig.options} are provided.
 */
export declare const connect: (connectionConfig: ConnectionConfig) => Promise<OpenFin.Fin<'external connection'>>;

export declare type ConnectionConfig = StandAloneConnectonConfig | InheritModeConnectConfig;

export declare type InheritModeConnectConfig = {
    /**
     * If 'enabled', connection option inheritance is enabled if the current browsing context is
     * a nested browsing context within an <of-view> element. This means that the brokerUrl and Identity
     * of the connection will be determined by the parent browsing context. Specifying a value is mandatory.
     */
    connectionInheritance: 'enabled';
    /**
     * Options used to connect to an OpenFin Web Broker. Please note, these will be overriden if connection inheritance
     * is enabled and supported for the current browsing context.
     */
    options?: BaseConnectionOptions;
    /**
     * Validates the inherited connection options from the parent browsing context, if available.
     * @param inheritedOptions Inherited options
     * @returns True if the connection options are accepted, or false otherwise.
     */
    validateOptions?: (inheritedOptions: Omit<BaseConnectionOptions, 'timeout'>) => boolean | Promise<boolean>;
};

export declare type StandAloneConnectonConfig = {
    /**
     * If 'enabled', connection option inheritance is enabled if the current browsing context is
     * a nested browsing context within an <of-view> element. This means that the brokerUrl and Identity
     * of the connection will be determined by the parent browsing context. Specifying a value is mandatory.
     */
    connectionInheritance?: 'disabled';
    /**
     * Options used to connect to an OpenFin Web Broker. Mandatory if {@link StandAloneConnectonConfig.connectionInheritance} is false.
     */
    options: BaseConnectionOptions;
};

export { }
