"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SendHttpRequestVariableSource = exports.SendHttpRequestStep = void 0;
const ConditionDescriptor_1 = require("../types/ConditionDescriptor");
const AbstractAssertionsAndVariablesStep_1 = require("./AbstractAssertionsAndVariablesStep");
class SendHttpRequestStep extends AbstractAssertionsAndVariablesStep_1.AbstractAssertionsAndVariablesStep {
    static stepName = 'SendHttpRequest';
    static actionCode = 'send_http_request';
    static mablScriptStepNames = [SendHttpRequestStep.actionCode];
    static yamlMablScriptNames = [SendHttpRequestStep.stepName];
    constructor(descriptor) {
        super(SendHttpRequestStep.stepName, descriptor, SendHttpRequestStep.actionCode);
        if (!this.isValidDescriptor(this.descriptor)) {
            throw new Error(`${SendHttpRequestStep.stepName}: descriptor.request must be defined`);
        }
    }
    isValidDescriptor(value) {
        return value.request !== undefined;
    }
    static fromYaml(_stepName, stepArgs) {
        const formatted = stepArgs;
        const comparisonTypeConverter = {
            Equals: ConditionDescriptor_1.AssertionConditionField.Equals,
            DoesNotEqual: ConditionDescriptor_1.AssertionConditionField.DoesNotEqual,
            Contains: ConditionDescriptor_1.AssertionConditionField.Contains,
            DoesNotContain: ConditionDescriptor_1.AssertionConditionField.DoesNotContain,
            StartsWith: ConditionDescriptor_1.AssertionConditionField.StartsWith,
            StartsWithout: ConditionDescriptor_1.AssertionConditionField.StartsWithout,
            EndsWith: ConditionDescriptor_1.AssertionConditionField.EndsWith,
            EndsWithout: ConditionDescriptor_1.AssertionConditionField.EndsWithout,
            GreaterThan: ConditionDescriptor_1.AssertionConditionField.GreaterThan,
            LessThan: ConditionDescriptor_1.AssertionConditionField.LessThan,
            GreaterThanOrEquals: ConditionDescriptor_1.AssertionConditionField.GreaterThanOrEquals,
            LessThanOrEquals: ConditionDescriptor_1.AssertionConditionField.LessThanOrEquals,
        };
        formatted.assertions?.forEach((assertion) => {
            if (assertion.assertion in comparisonTypeConverter) {
                assertion.assertion = comparisonTypeConverter[assertion.assertion];
            }
        });
        return new SendHttpRequestStep(formatted);
    }
    static fromLegacyMablscript(args, _actions) {
        if (args.length !== 1) {
            throw new Error(`SendHttpRequestStep fromLegacyMablscript expects 1 argument, got ${args.length}`);
        }
        return new SendHttpRequestStep(args[0]);
    }
}
exports.SendHttpRequestStep = SendHttpRequestStep;
var SendHttpRequestVariableSource;
(function (SendHttpRequestVariableSource) {
    SendHttpRequestVariableSource["Body"] = "body";
    SendHttpRequestVariableSource["Header"] = "header";
    SendHttpRequestVariableSource["Json"] = "json";
    SendHttpRequestVariableSource["Response"] = "response";
    SendHttpRequestVariableSource["Status"] = "status";
})(SendHttpRequestVariableSource || (exports.SendHttpRequestVariableSource = SendHttpRequestVariableSource = {}));
