import { ContextEvent } from '../BaseEvents.js';
import { TransportEventTypes } from './TransportEventTypes.js';
export const TransportEvent = Object.freeze({
    /**
     * Transport via the CoreEngine.
     */
    Core: Object.freeze({
        /**
         * Sends a single request without a context of a project.
         *
         * @param target The events target.
         * @param init The request execution configuration
         * @returns The execution log with the variables evaluated during the run or
         *          `undefined` when the event was not handled.
         */
        request: async (init, target = window) => {
            const e = new ContextEvent(TransportEventTypes.Core.request, init);
            target.dispatchEvent(e);
            return e.detail.result;
        },
        /**
         * For both the project or a folder (since it's all single configuration.)
         *
         * @param target The events target
         * @param init The project execution configuration
         */
        httpProject: async (init, target = window) => {
            const e = new ContextEvent(TransportEventTypes.Core.httpProject, init);
            target.dispatchEvent(e);
            return e.detail.result;
        },
    }),
    /**
     * Transport via the native platform's bindings.
     */
    Http: Object.freeze({
        /**
         * Sends the request outside the Core engine, most probably using Fetch API.
         * Note, CORS may apply to the request.
         *
         * @param target The events target
         * @param request The base request definition.
         * @param init Optional request init options compatible with the Fetch API.
         * @returns Compatible with the Fetch API Response object or `undefined` when the event was not handled.
         */
        send: async (request, init, target = window) => {
            const e = new ContextEvent(TransportEventTypes.Http.send, {
                request,
                init,
            });
            target.dispatchEvent(e);
            return e.detail.result;
        },
    }),
    // web sockets.
    Ws: Object.freeze({
        /**
         * Informs to make a connection. Used by web sockets.
         */
        connect: async (target) => {
            throw new Error(`Not yet implemented`);
        },
        /**
         * Informs to close the current connection. Used by web sockets.
         */
        disconnect: async (target) => {
            throw new Error(`Not yet implemented`);
        },
        /**
         * Informs to send a data on the current connection. Used by web sockets.
         */
        send: async (target) => {
            throw new Error(`Not yet implemented`);
        },
    }),
});
//# sourceMappingURL=TransportEvents.js.map