"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const OrderedFindStrategy_1 = __importDefault(require("../strategies/OrderedFindStrategy"));
const FindExactStrategy_1 = __importDefault(require("./FindExactStrategy"));
const FindBroadlyStrategy_1 = __importDefault(require("./FindBroadlyStrategy"));
const FindByXPathsStrategy_1 = __importDefault(require("./FindByXPathsStrategy"));
const FindSwitchStrategy_1 = __importDefault(require("./FindSwitchStrategy"));
const iOSWebViewFindStrategy_1 = __importDefault(require("./iOSWebViewFindStrategy"));
const AncestorAndTargetFindStrategy_1 = __importDefault(require("../strategies/AncestorAndTargetFindStrategy"));
const FindByTypeStrategy_1 = __importDefault(require("./FindByTypeStrategy"));
const WaitUntilFindStrategy_1 = require("../strategies/WaitUntilFindStrategy");
const VisualFindStrategy_1 = __importDefault(require("../strategies/VisualFindStrategy"));
const mablscriptFind_1 = require("@mablhq/test-model/mablscriptFind");
class iOSStrategy extends AncestorAndTargetFindStrategy_1.default {
    constructor(mobileFindExecutionConfig) {
        const { isRecordingWhileTrainingMode, isWaitUntilFind, maxFindExecutionTimeMs, onlyFindByXPath, primaryFindMethod, } = mobileFindExecutionConfig;
        const shouldSkipRetries = isRecordingWhileTrainingMode;
        let individualStrategy;
        let ancestorStrategy;
        if (isWaitUntilFind) {
            individualStrategy = new WaitUntilFindStrategy_1.WaitUntilFindStrategy(new FindByTypeStrategy_1.default(shouldSkipRetries));
            ancestorStrategy = individualStrategy;
        }
        else if (onlyFindByXPath) {
            individualStrategy = new OrderedFindStrategy_1.default([[new FindByXPathsStrategy_1.default(shouldSkipRetries)]], maxFindExecutionTimeMs, shouldSkipRetries);
            ancestorStrategy = individualStrategy;
        }
        else {
            const findByXpathStrategy = new FindByXPathsStrategy_1.default(shouldSkipRetries);
            const visualFindStrategy = new VisualFindStrategy_1.default();
            const nativeStrategies = [
                new iOSWebViewFindStrategy_1.default(shouldSkipRetries),
                new FindSwitchStrategy_1.default(shouldSkipRetries),
                new FindExactStrategy_1.default(shouldSkipRetries),
                new FindBroadlyStrategy_1.default(shouldSkipRetries),
            ];
            ancestorStrategy = new OrderedFindStrategy_1.default([nativeStrategies, [findByXpathStrategy]], maxFindExecutionTimeMs, shouldSkipRetries);
            const strategies = [];
            if (primaryFindMethod === mablscriptFind_1.PrimaryFindMethod.ELEMENT_DESCRIPTION) {
                strategies.push([visualFindStrategy]);
                strategies.push(nativeStrategies);
                strategies.push([findByXpathStrategy]);
            }
            else {
                strategies.push(nativeStrategies);
                strategies.push([findByXpathStrategy]);
                strategies.push([visualFindStrategy]);
            }
            individualStrategy = new OrderedFindStrategy_1.default(strategies, maxFindExecutionTimeMs, shouldSkipRetries);
        }
        super(mobileFindExecutionConfig, ancestorStrategy, individualStrategy);
    }
    getName() {
        return 'iOSStrategy';
    }
}
exports.default = iOSStrategy;
