import { EventTypes as CoreEventTypes } from '@api-client/core/build/browser.js';
import { PlatformBindings } from './PlatformBindings.js';
/**
 * The bindings for making HTTP request in the application.
 * The purpose is to run API requests using the `CoreEngine` class or
 * to run entire projects or folders.
 */
export class ProxyBindings extends PlatformBindings {
    constructor() {
        super(...arguments);
        /**
         * This is used by the client side (main thread or the renderer process)
         * to define the current space the app is using.
         * This space is used in some APIs instead of adding the space to the events system.
         */
        this.space = '';
    }
    async initialize() {
        window.addEventListener(CoreEventTypes.Transport.Core.request, this.handleCoreRequest.bind(this));
        window.addEventListener(CoreEventTypes.Transport.Core.httpProject, this.handleHttpProject.bind(this));
        window.addEventListener(CoreEventTypes.Transport.Http.send, this.handlerHttpSend.bind(this));
    }
    handleCoreRequest(e) {
        e.detail.result = this.coreRequest(e.detail);
    }
    handleHttpProject(e) {
        const copy = { ...e.detail };
        if (this.space && !copy.space) {
            copy.space = this.space;
        }
        e.detail.result = this.coreHttpProject(copy);
    }
    handlerHttpSend(e) {
        const { request, init } = e.detail;
        e.detail.result = this.httpSend(request, init);
    }
}
//# sourceMappingURL=ProxyBindings.js.map