export default {
  mixins: [],
  data: function () {
    return {
    }
  },
  created: function () {},
  mounted() {
    this.ruleWatcher()
    this.ruleCheck()
  },
  methods: {
    ruleWatcher() {
      const that = this;
      Object.keys(that.defaultRules).forEach(key => {
        that.$watch("model." + key, that.defaultRules[key])
      })
    },
    ruleCheck() {
      const keySet = new Set(Object.keys(this.pattern).concat(Object.keys(this.checkRules)))
      const res = {};
      for (let key of keySet.keys()) {
        const rule = []
        if(this.pattern[key]){
          rule.push(...this.pattern[key])
        } 
        if(this.checkRules[key]){
          for (let j = 0; j < this.checkRules[key].length; j++) {
            const check = this.checkRules[key][j];
            rule.push({
              validator: check
            })
          }
        }
        if(rule.length > 0) {
          res[key] = rule;
        }
      }
      this.rules = res;
    }
  }
}