"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("./wrap/lodash");
const is_matcher_1 = require("./matchers/is-matcher");
exports.default = (expectedArgs, actualArgs, config = {}) => {
    if (arityMismatch(expectedArgs, actualArgs, config)) {
        return false;
    }
    else if (config.allowMatchers !== false) {
        return equalsWithMatchers(expectedArgs, actualArgs);
    }
    else {
        return lodash_1.default.isEqual(expectedArgs, actualArgs);
    }
};
var arityMismatch = (expectedArgs, actualArgs, config) => expectedArgs.length !== actualArgs.length && !config.ignoreExtraArgs;
var equalsWithMatchers = (expectedArgs, actualArgs) => lodash_1.default.every(expectedArgs, (expectedArg, key) => argumentMatchesExpectation(expectedArg, actualArgs[key]));
var argumentMatchesExpectation = (expectedArg, actualArg) => {
    if (is_matcher_1.default(expectedArg)) {
        return matcherTestFor(expectedArg)(actualArg);
    }
    else {
        return lodash_1.default.isEqualWith(expectedArg, actualArg, (expectedEl, actualEl) => {
            if (is_matcher_1.default(expectedEl)) {
                return matcherTestFor(expectedEl)(actualEl);
            }
        });
    }
};
var matcherTestFor = (matcher) => matcher.__matches;
