"use strict";
/*
 * @adonisjs/validator
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mobile = void 0;
const isMobilePhone_1 = __importDefault(require("validator/lib/isMobilePhone"));
const helpers_1 = require("../../Validator/helpers");
const RULE_NAME = 'mobile';
const DEFAULT_MESSAGE = 'mobile validation failed';
/**
 * Validation signature for the "mobile" regex. Non-string values are
 * ignored.
 */
exports.mobile = {
    compile: (0, helpers_1.wrapCompile)(RULE_NAME, ['string'], ([options]) => {
        options = Object.assign({}, options);
        return {
            compiledOptions: {
                strict: options.strict || false,
                locale: options.locale,
            },
        };
    }),
    validate(value, compiledOptions, { errorReporter, arrayExpressionPointer, pointer }) {
        /**
         * Ignore non-string values. The user must apply string rule
         * to validate string.
         */
        if (typeof value !== 'string') {
            return;
        }
        /**
         * Invalid mobile number
         */
        if (!(0, isMobilePhone_1.default)(value, compiledOptions.locale, { strictMode: compiledOptions.strict })) {
            errorReporter.report(pointer, RULE_NAME, DEFAULT_MESSAGE, arrayExpressionPointer);
            return;
        }
    },
};
