"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rejectFlatLocator = rejectFlatLocator;
const FLAT_LOCATOR_MARKER = 'locator';
function collectLocatorPaths(value, path, out) {
    if (Array.isArray(value)) {
        value.forEach((entry, i) => collectLocatorPaths(entry, `${path}[${i}]`, out));
        return;
    }
    if (value && typeof value === 'object') {
        const obj = value;
        if (typeof obj[FLAT_LOCATOR_MARKER] === 'string') {
            out.push(path ? `${path}.${FLAT_LOCATOR_MARKER}` : FLAT_LOCATOR_MARKER);
        }
        for (const [key, entry] of Object.entries(obj)) {
            if (key === FLAT_LOCATOR_MARKER) {
                continue;
            }
            collectLocatorPaths(entry, path ? `${path}.${key}` : key, out);
        }
    }
}
const REMEDIATION = 'Edited finds must use the recorded trained descriptor shape (xpath plus ' +
    'attribute fields). Remove the "locator" field and edit the recorded ' +
    'selector instead.';
function rejectFlatLocator(steps) {
    const errors = [];
    steps.forEach((step, stepIndex) => {
        const paths = [];
        collectLocatorPaths(step, '', paths);
        for (const path of paths) {
            errors.push({
                step_index: stepIndex,
                path,
                detail: `Find descriptor uses the flat "locator" selector format at "${path}". ${REMEDIATION}`,
            });
        }
    });
    return errors;
}
