import { UMB_WEBHOOK_DETAIL_REPOSITORY_ALIAS } from '../repository/index.js';
import { UMB_WEBHOOK_ENTITY_TYPE, UMB_WEBHOOK_ROOT_ENTITY_TYPE, UMB_WEBHOOK_WORKSPACE_ALIAS } from '../../entity.js';
import { UmbWebhookWorkspaceEditorElement } from './webhook-workspace-editor.element.js';
import { UmbEntityNamedDetailWorkspaceContextBase, UmbWorkspaceIsNewRedirectController, UmbWorkspaceIsNewRedirectControllerAlias, } from '../../../core/workspace/index.js';
export class UmbWebhookWorkspaceContext extends UmbEntityNamedDetailWorkspaceContextBase {
    constructor(host) {
        super(host, {
            workspaceAlias: UMB_WEBHOOK_WORKSPACE_ALIAS,
            entityType: UMB_WEBHOOK_ENTITY_TYPE,
            detailRepositoryAlias: UMB_WEBHOOK_DETAIL_REPOSITORY_ALIAS,
        });
        // Observable states
        this.headers = this._data.createObservablePartOfCurrent((data) => data?.headers);
        this.enabled = this._data.createObservablePartOfCurrent((data) => data?.enabled);
        this.url = this._data.createObservablePartOfCurrent((data) => data?.url);
        this.description = this._data.createObservablePartOfCurrent((data) => data?.description);
        this.events = this._data.createObservablePartOfCurrent((data) => data?.events);
        this.contentTypes = this._data.createObservablePartOfCurrent((data) => data?.contentTypes);
        this.routes.setRoutes([
            {
                path: 'create',
                component: UmbWebhookWorkspaceEditorElement,
                setup: async () => {
                    await this.createScaffold({ parent: { entityType: UMB_WEBHOOK_ROOT_ENTITY_TYPE, unique: null } });
                    new UmbWorkspaceIsNewRedirectController(this, this, this.getHostElement().shadowRoot.querySelector('umb-router-slot'));
                },
            },
            {
                path: 'edit/:unique',
                component: UmbWebhookWorkspaceEditorElement,
                setup: (_component, info) => {
                    this.removeUmbControllerByAlias(UmbWorkspaceIsNewRedirectControllerAlias);
                    this.load(info.match.params.unique);
                },
            },
        ]);
    }
    /**
     * Sets the events
     * @param {Array<UmbWebhookEventModel>} events - The events
     * @memberof UmbWebhookWorkspaceContext
     */
    setEvents(events) {
        this._data.updateCurrent({ events });
    }
    /**
     * Gets the events
     * @returns {Array<UmbWebhookEventModel>}
     * @memberof UmbWebhookWorkspaceContext
     */
    getEvents() {
        return this._data.getCurrent()?.events;
    }
    /**
     * Sets the headers
     * @param {{ [key: string]: string }} headers - The headers
     * @memberof UmbWebhookWorkspaceContext
     */
    setHeaders(headers) {
        this._data.updateCurrent({ headers });
    }
    /**
     * Gets the headers
     * @returns {UmbWebhookDetailModel['headers']} - The headers
     * @memberof UmbWebhookWorkspaceContext
     */
    getHeaders() {
        return this._data.getCurrent()?.headers;
    }
    /**
     * Sets the content types
     * @param {string[]} types - The content types
     * @memberof UmbWebhookWorkspaceContext
     */
    setTypes(types) {
        this._data.updateCurrent({ contentTypes: types });
    }
    /**
     * Gets the content types
     * @returns {string[]} - The content types
     * @memberof UmbWebhookWorkspaceContext
     */
    getTypes() {
        return this._data.getCurrent()?.contentTypes;
    }
    /**
     * Sets the URL
     * @param {string} url - The URL
     * @memberof UmbWebhookWorkspaceContext
     */
    setUrl(url) {
        this._data.updateCurrent({ url });
    }
    /**
     * Sets the description
     * @param {string} description - The description
     * @memberof UmbWebhookWorkspaceContext
     */
    setDescription(description) {
        this._data.updateCurrent({ description });
    }
    /**
     * Gets the URL
     * @returns {string} - The URL
     * @memberof UmbWebhookWorkspaceContext
     */
    getUrl() {
        return this._data.getCurrent()?.url;
    }
    /**
     * Sets the enabled state
     * @param {boolean} enabled - The enabled state
     * @memberof UmbWebhookWorkspaceContext
     */
    setEnabled(enabled) {
        this._data.updateCurrent({ enabled });
    }
    /**
     * Gets the enabled state
     * @returns {boolean} - The enabled state
     * @memberof UmbWebhookWorkspaceContext
     */
    getEnabled() {
        return this._data.getCurrent()?.enabled;
    }
}
export { UmbWebhookWorkspaceContext as api };
