import { EventTypes } from './EventTypes.js';
import { ContextDeleteEvent, ContextQueryEvent } from '@api-client/core/events/BaseEvents.js';
export default Object.freeze({
    Model: Object.freeze({
        UrlHistory: Object.freeze({
            /**
             * Adds a new URL to the URL history store.
             * @param url the URL to store.
             * @param target Optional events target
             */
            add: async (url, target = document.body) => {
                const e = new CustomEvent(EventTypes.HttpClient.Model.UrlHistory.add, {
                    bubbles: true,
                    cancelable: true,
                    composed: true,
                    detail: {
                        url,
                        result: undefined,
                    },
                });
                target.dispatchEvent(e);
                await e.detail.result;
            },
            /**
             * Queries for the URL history data.
             * @param q The part of URL to query for.
             * @param target Optional events target
             */
            query: async (q, target = document.body) => {
                const e = new ContextQueryEvent(EventTypes.HttpClient.Model.UrlHistory.query, {
                    term: q,
                });
                target.dispatchEvent(e);
                return e.detail.result;
            },
            /**
             * Deletes a single URL from the store.
             * @param url The full stored URL to remove
             * @param target Optional events target
             */
            delete: async (url, target = document.body) => {
                const e = new ContextDeleteEvent(EventTypes.HttpClient.Model.UrlHistory.delete, url);
                target.dispatchEvent(e);
                await e.detail.result;
            },
            /**
             * Clears the URL history store completely.
             * @param target Optional events target
             */
            clear: async (target = document.body) => {
                const e = new CustomEvent(EventTypes.HttpClient.Model.UrlHistory.clear, {
                    bubbles: true,
                    cancelable: true,
                    composed: true,
                    detail: {
                        result: undefined,
                    },
                });
                target.dispatchEvent(e);
                await e.detail.result;
            },
            State: Object.freeze({
                /**
                 * Notifies the application a history URL has been added to the store.
                 * @param target Optional events target
                 */
                add: (entity, target = document.body) => {
                    const e = new CustomEvent(EventTypes.HttpClient.Model.UrlHistory.State.add, {
                        bubbles: true,
                        cancelable: false,
                        composed: true,
                        detail: entity,
                    });
                    target.dispatchEvent(e);
                },
                /**
                 * Notifies the application that the history store has been cleared.
                 * @param target Optional events target
                 */
                clear: (target = document.body) => {
                    const e = new Event(EventTypes.HttpClient.Model.UrlHistory.State.clear, {
                        bubbles: true,
                        cancelable: false,
                        composed: true,
                    });
                    target.dispatchEvent(e);
                },
                /**
                 * Notifies the application a history URL has been removed from the store.
                 * @param target Optional events target
                 */
                delete: (url, target = document.body) => {
                    const e = new CustomEvent(EventTypes.HttpClient.Model.UrlHistory.State.delete, {
                        bubbles: true,
                        cancelable: false,
                        composed: true,
                        detail: url,
                    });
                    target.dispatchEvent(e);
                },
            }),
        }),
        WsHistory: Object.freeze({
            /**
             * Adds a new URL to the web socket history store.
             * @param url the URL to store.
             * @param target Optional events target
             */
            add: async (url, target = document.body) => {
                const e = new CustomEvent(EventTypes.HttpClient.Model.WsHistory.add, {
                    bubbles: true,
                    cancelable: true,
                    composed: true,
                    detail: {
                        url,
                        result: undefined,
                    },
                });
                target.dispatchEvent(e);
                await e.detail.result;
            },
            /**
             * Queries for the seb socket URL history data.
             * @param q The part of URL to query for.
             * @param target Optional events target
             */
            query: async (q, target = document.body) => {
                const e = new ContextQueryEvent(EventTypes.HttpClient.Model.WsHistory.query, {
                    term: q,
                });
                target.dispatchEvent(e);
                return e.detail.result;
            },
            /**
             * Deletes a single web socket URL from the store.
             * @param url The full stored URL to remove
             * @param target Optional events target
             */
            delete: async (url, target = document.body) => {
                const e = new ContextDeleteEvent(EventTypes.HttpClient.Model.WsHistory.delete, url);
                target.dispatchEvent(e);
                await e.detail.result;
            },
            /**
             * Clears the web socket URL history store completely.
             * @param target Optional events target
             */
            clear: async (target = document.body) => {
                const e = new CustomEvent(EventTypes.HttpClient.Model.WsHistory.clear, {
                    bubbles: true,
                    cancelable: true,
                    composed: true,
                    detail: {
                        result: undefined,
                    },
                });
                target.dispatchEvent(e);
                await e.detail.result;
            },
            State: Object.freeze({
                /**
                 * Notifies the application a history URL has been added to the store.
                 * @param target Optional events target
                 */
                add: (entity, target = document.body) => {
                    const e = new CustomEvent(EventTypes.HttpClient.Model.WsHistory.State.add, {
                        bubbles: true,
                        cancelable: false,
                        composed: true,
                        detail: entity,
                    });
                    target.dispatchEvent(e);
                },
                /**
                 * Notifies the application that the web socket history store has been cleared.
                 * @param target Optional events target
                 */
                clear: (target = document.body) => {
                    const e = new Event(EventTypes.HttpClient.Model.WsHistory.State.clear, {
                        bubbles: true,
                        cancelable: false,
                        composed: true,
                    });
                    target.dispatchEvent(e);
                },
                /**
                 * Notifies the application a web socket history URL has been removed from the store.
                 * @param target Optional events target
                 */
                delete: (url, target = document.body) => {
                    const e = new CustomEvent(EventTypes.HttpClient.Model.WsHistory.State.delete, {
                        bubbles: true,
                        cancelable: false,
                        composed: true,
                        detail: url,
                    });
                    target.dispatchEvent(e);
                },
            }),
        }),
    }),
});
//# sourceMappingURL=HttpClientEvents.js.map