import { __esDecorate, __runInitializers } from "tslib";
import { html } from 'lit';
import { property } from 'lit/decorators.js';
import { ApiDocumentationBase } from './ApiDocumentationBase.js';
import { Events } from '../../events/amf/Events.js';
import '../../define/amf/api-parametrized-security-scheme.js';
let ApiSecurityRequirementDocument = (() => {
    let _classSuper = ApiDocumentationBase;
    let _instanceExtraInitializers = [];
    let _set_securityRequirement_decorators;
    return class ApiSecurityRequirementDocument extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _set_securityRequirement_decorators = [property({ type: Object })];
            __esDecorate(this, null, _set_securityRequirement_decorators, { kind: "setter", name: "securityRequirement", static: false, private: false, access: { has: obj => "securityRequirement" in obj, set: (obj, value) => { obj.securityRequirement = value; } }, metadata: _metadata }, null, _instanceExtraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        securityRequirementValue = __runInitializers(this, _instanceExtraInitializers);
        get securityRequirement() {
            return this.securityRequirementValue;
        }
        set securityRequirement(value) {
            const old = this.securityRequirementValue;
            if (old === value) {
                return;
            }
            this.securityRequirementValue = value;
            this.processGraph();
        }
        async processGraph() {
            await this.querySecurity();
            this.requestUpdate();
        }
        /**
         * Queries for the security requirements object.
         */
        async querySecurity() {
            const { domainId } = this;
            if (!domainId) {
                // this[securityValue] = undefined;
                return;
            }
            if (this.securityRequirementValue && this.securityRequirementValue.id === domainId) {
                // in case the security model was provided via the property setter.
                return;
            }
            try {
                const info = await Events.Security.getRequirement(this, domainId);
                this.securityRequirementValue = info;
            }
            catch (e) {
                const ex = e;
                this.securityRequirementValue = undefined;
                Events.Telemetry.exception(this, ex.message, false);
                Events.Reporting.error(this, ex, `Unable to query for API operation data: ${ex.message}`, this.localName);
            }
        }
        render() {
            const scheme = this.securityRequirementValue;
            if (!scheme || !scheme.schemes || !scheme.schemes.length) {
                return html ``;
            }
            return html `
      <div class="security-requirements">
        ${scheme.schemes.map((item) => html ` <api-parametrized-security-scheme
              .securityScheme="${item.scheme}"
              .settings="${item.settings}"
              settingsOpened
            ></api-parametrized-security-scheme>`)}
      </div>
    `;
        }
    };
})();
export default ApiSecurityRequirementDocument;
//# sourceMappingURL=ApiSecurityRequirementDocument.element.js.map