import { EventTypes } from './EventTypes.js';
export default Object.freeze({
    Session: Object.freeze({
        /**
         * Sets a config property that is held in the storage only for the time of the current session.
         *
         * @param key The key under to store the value.
         * @param value The value to store. If this is not a primitive it will be serialized with `JSON.stringify()`.
         */
        set: async (key, value, target = document.body) => {
            const e = new CustomEvent(EventTypes.Config.Session.set, {
                bubbles: true,
                cancelable: true,
                composed: true,
                detail: {
                    key,
                    value,
                    result: undefined,
                },
            });
            target.dispatchEvent(e);
            await e.detail.result;
        },
        /**
         * Reads a previously stored session value.
         *
         * @param key The key under which the property was stored.
         */
        get: async (key, target = document.body) => {
            const e = new CustomEvent(EventTypes.Config.Session.get, {
                bubbles: true,
                cancelable: true,
                composed: true,
                detail: {
                    key,
                    result: undefined,
                },
            });
            target.dispatchEvent(e);
            return e.detail.result;
        },
        /**
         * Deletes previously stored session value.
         *
         * @param key The key under which the property was stored.
         */
        delete: async (key, target = document.body) => {
            const e = new CustomEvent(EventTypes.Config.Session.delete, {
                bubbles: true,
                cancelable: true,
                composed: true,
                detail: {
                    key,
                    result: undefined,
                },
            });
            target.dispatchEvent(e);
            await e.detail.result;
        },
    }),
    Local: Object.freeze({
        /**
         * Sets a config property that is permanently stored.
         * This is not the same as application configuration. This can be used to store specific configuration
         * property for a single view.
         *
         * @param key The key under to store the value.
         * @param value The value to store. If this is not a primitive it will be serialized with `JSON.stringify()`.
         */
        set: async (key, value, target = document.body) => {
            const e = new CustomEvent(EventTypes.Config.Local.set, {
                bubbles: true,
                cancelable: true,
                composed: true,
                detail: {
                    key,
                    value,
                    result: undefined,
                },
            });
            target.dispatchEvent(e);
            await e.detail.result;
        },
        /**
         * Reads a previously stored local value.
         *
         * @param key The key under which the property was stored.
         * @param globalKey If known, the key of the configuration property in the application
         * global configuration. When set and the value in the local storage is not set, then
         * the config store reads the value from the application configuration.
         */
        get: async (key, globalKey, target = document.body) => {
            const e = new CustomEvent(EventTypes.Config.Local.get, {
                bubbles: true,
                cancelable: true,
                composed: true,
                detail: {
                    key,
                    globalKey,
                    result: undefined,
                },
            });
            target.dispatchEvent(e);
            return e.detail.result;
        },
        /**
         * Deletes previously stored local value.
         *
         * @param key The key under which the property was stored.
         */
        delete: async (key, target = document.body) => {
            const e = new CustomEvent(EventTypes.Config.Local.delete, {
                bubbles: true,
                cancelable: true,
                composed: true,
                detail: {
                    key,
                    result: undefined,
                },
            });
            target.dispatchEvent(e);
            await e.detail.result;
        },
    }),
    Telemetry: Object.freeze({
        /**
         * Sets the configuration for telemetry.
         *
         * @param config The configuration to set.
         * @param target Optional events target.
         */
        set: async (config, target = document.body) => {
            const e = new CustomEvent(EventTypes.Config.Telemetry.set, {
                bubbles: true,
                cancelable: true,
                composed: true,
                detail: {
                    config,
                    result: undefined,
                },
            });
            target.dispatchEvent(e);
            await e.detail.result;
        },
        /**
         * Reads the set telemetry configuration. If the configuration is missing a default value is returned.
         *
         * @param target Optional events target
         */
        read: async (target = document.body) => {
            const e = new CustomEvent(EventTypes.Config.Telemetry.read, {
                bubbles: true,
                cancelable: true,
                composed: true,
                detail: {
                    result: undefined,
                },
            });
            target.dispatchEvent(e);
            return e.detail.result;
        },
        State: Object.freeze({
            /**
             * Dispatched to inform the application that the new telemetry state has been set.
             *
             * @param config The set configuration.
             * @param target Optional events target.
             */
            set: (config, target = document.body) => {
                const e = new CustomEvent(EventTypes.Config.Telemetry.State.set, {
                    bubbles: true,
                    cancelable: true,
                    composed: true,
                    detail: config,
                });
                target.dispatchEvent(e);
            },
        }),
    }),
});
//# sourceMappingURL=ConfigEvents.js.map