"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 FindBroadlyStrategy_1 = __importDefault(require("./FindBroadlyStrategy"));
const FindByXPathsStrategy_1 = __importDefault(require("./FindByXPathsStrategy"));
const AndroidWebViewFindStrategy_1 = __importDefault(require("./AndroidWebViewFindStrategy"));
const AncestorAndTargetFindStrategy_1 = __importDefault(require("../strategies/AncestorAndTargetFindStrategy"));
const WaitUntilFindStrategy_1 = require("../strategies/WaitUntilFindStrategy");
const FindByClassStrategy_1 = __importDefault(require("./FindByClassStrategy"));
const VisualFindStrategy_1 = __importDefault(require("../strategies/VisualFindStrategy"));
const mablscriptFind_1 = require("@mablhq/test-model/mablscriptFind");
class AndroidStrategy 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 FindByClassStrategy_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 AndroidWebViewFindStrategy_1.default(shouldSkipRetries),
                new FindBroadlyStrategy_1.default(shouldSkipRetries),
                new FindByClassStrategy_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 'AndroidStrategy';
    }
}
exports.default = AndroidStrategy;
