"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AssertionConditionFieldToStepName = exports.AssertionStepNameToField = exports.PresenceEvaluationType = exports.AssertionConditionField = exports.ConditionType = void 0;
exports.isComparisonType = isComparisonType;
exports.getOptionalComparisonType = getOptionalComparisonType;
exports.getOptionalComparatorValue = getOptionalComparatorValue;
exports.getOptionalConditionOptions = getOptionalConditionOptions;
exports.isPresenceCondition = isPresenceCondition;
exports.isAIPromptCondition = isAIPromptCondition;
exports.isAbsenceExpected = isAbsenceExpected;
exports.getAssertionConditionFieldFromDescriptor = getAssertionConditionFieldFromDescriptor;
const MablSymbol_1 = require("../MablSymbol");
var ConditionType;
(function (ConditionType) {
    ConditionType["AIPrompt"] = "ai_prompt";
    ConditionType["Comparison"] = "comparison";
    ConditionType["Presence"] = "presence";
    ConditionType["Truthy"] = "truthy";
})(ConditionType || (exports.ConditionType = ConditionType = {}));
exports.AssertionConditionField = {
    Equals: 'equals',
    Present: 'present',
    NotPresent: 'not_present',
    DoesNotEqual: 'does_not_equal',
    Contains: 'contains',
    DoesNotContain: 'does_not_contain',
    StartsWith: 'starts_with',
    StartsWithout: 'starts_without',
    EndsWith: 'ends_with',
    EndsWithout: 'ends_without',
    GreaterThan: 'greater_than',
    LessThan: 'less_than',
    MatchesRegex: 'matches_regex',
    GreaterThanOrEquals: 'greater_than_or_equals',
    LessThanOrEquals: 'less_than_or_equals',
    AIPrompt: 'ai_prompt',
};
function isComparisonType(text) {
    return Object.values(exports.AssertionConditionField)
        .filter((field) => field !== exports.AssertionConditionField.Present &&
        field !== exports.AssertionConditionField.NotPresent &&
        field !== exports.AssertionConditionField.AIPrompt)
        .map((field) => field)
        .includes(text);
}
function getOptionalComparisonType(descriptor) {
    if (descriptor === undefined) {
        return undefined;
    }
    if (descriptor.conditionType === ConditionType.Comparison) {
        return descriptor.comparisonType;
    }
    return undefined;
}
function getOptionalComparatorValue(descriptor) {
    if (descriptor?.conditionType !== ConditionType.Comparison) {
        return undefined;
    }
    return (0, MablSymbol_1.isMablSymbolObject)(descriptor.comparatorValue)
        ? `{{@${descriptor.comparatorValue.name}}}`
        : descriptor.comparatorValue;
}
function getOptionalConditionOptions(descriptor) {
    if (descriptor === undefined ||
        descriptor.conditionType !== ConditionType.Comparison) {
        return undefined;
    }
    if (descriptor.caseInsensitive !== undefined) {
        return { caseInsensitive: descriptor.caseInsensitive };
    }
    return {};
}
function isPresenceCondition(value) {
    return value.conditionType === ConditionType.Presence;
}
function isAIPromptCondition(value) {
    return value.conditionType === ConditionType.AIPrompt;
}
function isAbsenceExpected(value) {
    return (isPresenceCondition(value) &&
        value.presenceType === PresenceEvaluationType.NOT_PRESENT);
}
var PresenceEvaluationType;
(function (PresenceEvaluationType) {
    PresenceEvaluationType["NOT_PRESENT"] = "not_present";
    PresenceEvaluationType["PRESENT"] = "present";
})(PresenceEvaluationType || (exports.PresenceEvaluationType = PresenceEvaluationType = {}));
(function (PresenceEvaluationType) {
    function fromString(value) {
        const result = value;
        if (!Object.values(PresenceEvaluationType).includes(result)) {
            throw new Error(`No PresenceEvaluationType match found for value: ${value}`);
        }
        return result;
    }
    PresenceEvaluationType.fromString = fromString;
})(PresenceEvaluationType || (exports.PresenceEvaluationType = PresenceEvaluationType = {}));
function getAssertionConditionFieldFromDescriptor(conditionDescriptor) {
    if (conditionDescriptor === undefined) {
        return undefined;
    }
    if (conditionDescriptor.conditionType === ConditionType.Comparison) {
        return conditionDescriptor.comparisonType;
    }
    if (conditionDescriptor.conditionType === ConditionType.Presence) {
        return conditionDescriptor.presenceType;
    }
    if (conditionDescriptor.conditionType === ConditionType.AIPrompt) {
        return 'ai_prompt';
    }
    return undefined;
}
exports.AssertionStepNameToField = {
    AssertEquals: 'equals',
    AssertPresent: 'present',
    AssertNotPresent: 'not_present',
    AssertDoesNotEqual: 'does_not_equal',
    AssertContains: 'contains',
    AssertDoesNotContain: 'does_not_contain',
    AssertStartsWith: 'starts_with',
    AssertStartsWithout: 'starts_without',
    AssertEndsWith: 'ends_with',
    AssertEndsWithout: 'ends_without',
    AssertGreaterThan: 'greater_than',
    AssertLessThan: 'less_than',
    AssertGreaterThanOrEquals: 'greater_than_or_equals',
    AssertLessThanOrEquals: 'less_than_or_equals',
    AssertMatchesRegex: 'matches_regex',
    AssertAIPrompt: 'ai_prompt',
};
exports.AssertionConditionFieldToStepName = Object.fromEntries(Object.entries(exports.AssertionStepNameToField).map(([stepType, field]) => [
    field,
    stepType,
]));
