import { HttpStep } from '../../HttpStep.js';
export const MatchesSchemaAssertionKind = 'HttpAction#MatchesSchemaAssertion';
/**
 * An assertion that makes sure the input matches a JSON schema. The input has to be
 * a valid JSON string, object, or an array.
 */
export class MatchesSchemaAssertion extends HttpStep {
    kind = MatchesSchemaAssertionKind;
    /**
     * The application internal reference to the schema stored in a store.
     */
    ref;
    /**
     * When set it ignores the `ref` and uses this JSON schema to validate the input against.
     */
    schema;
    static fromRef(ref) {
        return new MatchesSchemaAssertion({
            kind: MatchesSchemaAssertionKind,
            enabled: true,
            ref,
        });
    }
    static fromSchema(schema) {
        return new MatchesSchemaAssertion({
            kind: MatchesSchemaAssertionKind,
            enabled: true,
            schema,
        });
    }
    constructor(init) {
        super();
        if (typeof init === 'object') {
            this.new(init);
        }
    }
    new(init) {
        super.new(init);
        this.kind = MatchesSchemaAssertionKind;
        this.ref = init.ref;
        this.schema = init.schema;
    }
    checkValidity() {
        return !!this.schema || !!this.ref;
    }
    toJSON() {
        const result = {
            ...super.toJSON(),
            kind: MatchesSchemaAssertionKind,
        };
        if (this.ref) {
            result.ref = this.ref;
        }
        if (this.schema) {
            result.schema = this.schema;
        }
        return result;
    }
}
//# sourceMappingURL=MatchesSchemaAssertion.js.map