"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllStepJsonSchemas = exports.getStepJsonSchema = void 0;
exports.validate = validate;
exports.validateTest = validateTest;
exports.validateStep = validateStep;
exports.getStepSchema = getStepSchema;
exports.getStepTypeNames = getStepTypeNames;
exports.getBrowserStepsUnionSchema = getBrowserStepsUnionSchema;
const errors_1 = require("./errors");
const step_registry_1 = require("./schemas/step-registry");
const structural_1 = require("./validation/structural");
const cross_step_1 = require("./validation/cross-step");
const semantic_1 = require("./validation/semantic");
const options_1 = require("./validation/options");
const test_level_1 = require("./validation/test-level");
var json_schema_1 = require("./json-schema");
Object.defineProperty(exports, "getStepJsonSchema", { enumerable: true, get: function () { return json_schema_1.getStepJsonSchema; } });
Object.defineProperty(exports, "getAllStepJsonSchemas", { enumerable: true, get: function () { return json_schema_1.getAllStepJsonSchemas; } });
function validate(jsonSteps, options) {
    const resolved = (0, options_1.resolveOptions)(options);
    const structuralResult = (0, structural_1.validateStructure)(jsonSteps, resolved);
    if (!structuralResult.valid) {
        return structuralResult;
    }
    const steps = jsonSteps.steps;
    const resultsToMerge = [structuralResult];
    if (resolved.semanticValidation !== false) {
        resultsToMerge.push((0, semantic_1.validateSemantics)(steps, resolved));
    }
    if (resolved.crossStepValidation !== false) {
        resultsToMerge.push((0, cross_step_1.validateConditionalBlocks)(steps, resolved));
        resultsToMerge.push((0, cross_step_1.validateVariableOrder)(steps));
    }
    return (0, errors_1.mergeResults)(...resultsToMerge);
}
function validateTest(flows, options) {
    return (0, test_level_1.validateTestFlows)(flows, (0, options_1.resolveOptions)(options));
}
function validateStep(step, options) {
    const resolved = (0, options_1.resolveOptions)(options);
    const structuralResult = (0, structural_1.validateStepStructure)(step, 0, resolved);
    if (!structuralResult.valid || resolved.semanticValidation === false) {
        return structuralResult;
    }
    const semanticResult = (0, semantic_1.validateStepSemantics)(step, 0, resolved);
    return (0, errors_1.mergeResults)(structuralResult, semanticResult);
}
function getStepSchema(stepTypeName, testType) {
    return (0, step_registry_1.getStepSchema)(stepTypeName, testType);
}
function getStepTypeNames(testType) {
    return (0, step_registry_1.getStepTypeNames)(testType);
}
function getBrowserStepsUnionSchema() {
    return (0, step_registry_1.getBrowserStepsUnionSchema)();
}
