import { __esDecorate, __runInitializers } from "tslib";
import { RateLimitingConfiguration } from '../rules/RateLimitingConfiguration.js';
import { observed } from '../../decorators/observed.js';
import { restoreAccessRule } from '../rules/index.js';
/**
 * A base class for common properties across all actions.
 */
let Action = (() => {
    let _classSuper = EventTarget;
    let _kind_decorators;
    let _kind_initializers = [];
    let _kind_extraInitializers = [];
    let _accessRule_decorators;
    let _accessRule_initializers = [];
    let _accessRule_extraInitializers = [];
    let _rateLimiting_decorators;
    let _rateLimiting_initializers = [];
    let _rateLimiting_extraInitializers = [];
    return class Action extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _kind_decorators = [observed()];
            _accessRule_decorators = [observed({ deep: true })];
            _rateLimiting_decorators = [observed({ deep: true })];
            __esDecorate(this, null, _kind_decorators, { kind: "accessor", name: "kind", static: false, private: false, access: { has: obj => "kind" in obj, get: obj => obj.kind, set: (obj, value) => { obj.kind = value; } }, metadata: _metadata }, _kind_initializers, _kind_extraInitializers);
            __esDecorate(this, null, _accessRule_decorators, { kind: "accessor", name: "accessRule", static: false, private: false, access: { has: obj => "accessRule" in obj, get: obj => obj.accessRule, set: (obj, value) => { obj.accessRule = value; } }, metadata: _metadata }, _accessRule_initializers, _accessRule_extraInitializers);
            __esDecorate(this, null, _rateLimiting_decorators, { kind: "accessor", name: "rateLimiting", static: false, private: false, access: { has: obj => "rateLimiting" in obj, get: obj => obj.rateLimiting, set: (obj, value) => { obj.rateLimiting = value; } }, metadata: _metadata }, _rateLimiting_initializers, _rateLimiting_extraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        #kind_accessor_storage = __runInitializers(this, _kind_initializers, void 0);
        get kind() { return this.#kind_accessor_storage; }
        set kind(value) { this.#kind_accessor_storage = value; }
        #accessRule_accessor_storage = (__runInitializers(this, _kind_extraInitializers), __runInitializers(this, _accessRule_initializers, void 0));
        get accessRule() { return this.#accessRule_accessor_storage; }
        set accessRule(value) { this.#accessRule_accessor_storage = value; }
        #rateLimiting_accessor_storage = (__runInitializers(this, _accessRule_extraInitializers), __runInitializers(this, _rateLimiting_initializers, void 0));
        get rateLimiting() { return this.#rateLimiting_accessor_storage; }
        set rateLimiting(value) { this.#rateLimiting_accessor_storage = value; }
        constructor(state = {}) {
            super();
            __runInitializers(this, _rateLimiting_extraInitializers);
            this.kind = state.kind || '';
            this.accessRule = state.accessRule ? state.accessRule.map((rule) => restoreAccessRule(rule)) : [];
            this.rateLimiting = state.rateLimiting ? new RateLimitingConfiguration(state.rateLimiting) : undefined;
        }
        notifyChange() {
            this.dispatchEvent(new Event('change'));
        }
        toJSON() {
            const result = {
                kind: this.kind,
            };
            if (this.accessRule.length) {
                result.accessRule = this.accessRule.map((rule) => rule.toJSON());
            }
            if (this.rateLimiting) {
                result.rateLimiting = this.rateLimiting.toJSON();
            }
            return result;
        }
    };
})();
export { Action };
//# sourceMappingURL=Action.js.map