export const Kind = 'Core#RequestAuthorization';
export class RequestAuthorization {
    kind = Kind;
    /**
     * Authorization configuration
     */
    config;
    /**
     * The name of the authorization
     */
    type;
    /**
     * Whether the authorization is enabled.
     */
    enabled;
    /**
     * Whether the authorization is reported to be valid.
     * The application should take action when the authorization is invalid but possibly allow the request.
     */
    valid;
    static fromTypedConfig(type, config, valid = true) {
        return new RequestAuthorization({
            kind: Kind,
            config,
            enabled: true,
            type,
            valid,
        });
    }
    static fromLegacy(info) {
        const copy = { ...info };
        if (copy.type === 'client certificate') {
            copy.config = {};
        }
        return new RequestAuthorization({
            kind: Kind,
            config: info.config,
            enabled: true,
            type: info.type,
            valid: info.valid,
        });
    }
    /**
     * @param input The provider definition used to restore the state.
     */
    constructor(input) {
        let init;
        if (typeof input === 'string') {
            init = JSON.parse(input);
        }
        else if (typeof input === 'object') {
            init = input;
        }
        else {
            init = {
                kind: Kind,
                config: {},
                enabled: false,
                type: '',
                valid: true,
            };
        }
        this.new(init);
    }
    /**
     * Creates a new request authorization clearing anything that is so far defined.
     */
    new(init) {
        const { config, type, enabled, valid } = init;
        this.kind = Kind;
        this.config = config;
        this.type = type;
        this.enabled = enabled;
        this.valid = valid;
    }
    toJSON() {
        const { config = {} } = this;
        const result = {
            kind: Kind,
            config: { ...config },
            enabled: this.enabled || false,
            type: this.type || '',
            valid: this.valid || true,
        };
        return result;
    }
}
//# sourceMappingURL=RequestAuthorization.js.map