import _ from 'lodash/fp';
import required from './required';

class And {
  constructor(mappings) {
    this.mappings = mappings;
  }

  satisfied(inputObj) {
    const equalInput = function (mapping) {
      return _.get(mapping.key, inputObj) === mapping.value;
    };

    return _.every(equalInput, this.mappings);
  }
}

class Or {
  constructor(mappings) {
    this.mappings = mappings;
  }

  satisfied(inputObj) {
    const equalInput = function (mapping) {
      return _.get(mapping.key, inputObj) === mapping.value;
    };

    return _.some(equalInput, this.mappings);
  }
}

const validate = (val, ruleObj, propertyName, inputObj) => {
  const targetProperty = ruleObj.params[0];

  if ((targetProperty instanceof And && targetProperty.satisifed(inputObj)) ||
      (targetProperty instanceof Or && targetProperty.satisfied(inputObj)) ||
      (inputObj[targetProperty] === ruleObj.params[1])) {
    return required.validate(val);
  }

  return true;
};

const message = required.message;

export default {validate, message, And, Or};

@@ -86,32 +86,55 @@
 tor(mappings) %7B%0A
+    this.type = 'and';%0A
     this.mapping
@@ -372,32 +372,54 @@
 tor(mappings) %7B%0A
+    this.type = 'or';%0A
     this.mapping
@@ -627,16 +627,297 @@
 %0A  %7D%0A%7D%0A%0A
+const isAnd = structure =%3E %7B%0A  return structure instanceof And %7C%7C structure.type === 'and';%0A%7D;%0A%0Aconst isOr = structure =%3E %7B%0A  return structure instanceof Or %7C%7C structure.type === 'or';%0A%7D;%0A%0Aconst shouldUseSatisfied = structure =%3E %7B%0A  return isAnd(structure) %7C%7C isOr(structure);%0A%7D;%0A%0A
 const va
@@ -1025,115 +1025,42 @@
 f ((
-targetProperty instanceof And && targetProperty.s
+shouldUseS
 atis
-i
 f
+i
 ed(
-inputObj)) %7C%7C%0A      (targetProperty instanceof Or
+targetProperty)
  && 

Add type to required-if parameter data structure