'use strict';

var utils = require('../utils');

module.exports = function(existing, app) {
  existing = utils.arrayify(existing);
  
  return {
    type: ['array'],
    normalize: function(val, key, config, schema) {
      if (!val) return;

      if (typeof val === 'string') {
        val = val.split(',');
      }

      if (utils.isObject(val)) {
        for (var prop in val) {
          var value = val[prop];
          if (typeof value === 'boolean') {
            val = [prop];
          }
        }
      }

      if (Array.isArray(val)) {
        val = utils.union([], existing, val);
        if (val.length) {
          return val;
        }
      }
      return null;
    }
  };
};

@@ -124,18 +124,16 @@
 sting);%0A
-  
 %0A  retur
@@ -609,24 +609,53 @@
 l.length) %7B%0A
+          config%5Bkey%5D = val;%0A
           re

update value on `config` in case the reference is broken