"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const AppiumLocatorBuilderBase_1 = __importStar(require("../AppiumLocatorBuilderBase"));
const NO_CLAUSES_ERROR_MESSAGE = 'An iOS predicate cannot be generated when there are no valid clauses to narrow down the results.';
class iOSPredicateBuilder extends AppiumLocatorBuilderBase_1.default {
    name(value, comparator = AppiumLocatorBuilderBase_1.AppiumClauseComparator.Equals) {
        return this.pushString('name', value, comparator);
    }
    label(value, comparator = AppiumLocatorBuilderBase_1.AppiumClauseComparator.Equals) {
        return this.pushString('label', value, comparator);
    }
    type(value) {
        return this.pushString('type', value);
    }
    visible(value) {
        return this.pushBoolean('visible', value);
    }
    accessible(value) {
        return this.pushBoolean('accessible', value);
    }
    value(value, comparator = AppiumLocatorBuilderBase_1.AppiumClauseComparator.Equals) {
        return this.pushString('value', value, comparator);
    }
    toLocatorString() {
        if (!this.hasAnyClause()) {
            throw new Error(NO_CLAUSES_ERROR_MESSAGE);
        }
        return (`${AppiumLocatorBuilderBase_1.AppiumLocatorStrategy.iOSPredicateString}:` +
            this.clauses.join(' AND '));
    }
    toLocator() {
        if (!this.hasAnyClause()) {
            throw new Error(NO_CLAUSES_ERROR_MESSAGE);
        }
        return {
            strategy: AppiumLocatorBuilderBase_1.AppiumLocatorStrategy.iOSPredicateString,
            appiumSelector: this.clauses.join(' AND '),
        };
    }
    getStringClause(key, value, comparator) {
        const comparatorSymbol = comparator === AppiumLocatorBuilderBase_1.AppiumClauseComparator.Equals ? '==' : ' CONTAINS ';
        return `${key}${comparatorSymbol}"${this.sanitizeInput(value)}"`;
    }
    getBooleanClause(key, value) {
        return `${key}==${value ? '1' : '0'}`;
    }
    getNumberClause(key, value) {
        return `${key}==${value}`;
    }
}
exports.default = iOSPredicateBuilder;
