// Generated by CoffeeScript 2.3.2
(function() {
  var Attribute, Simple;

  Attribute = require('./attribute');

  module.exports = Simple = class Simple extends Attribute {
    aggregation() {
      var ref;
      return {
        terms: {
          field: this.field,
          size: (ref = this._options.buckets) != null ? ref : 0
        }
      };
    }

    filter(paramString) {
      var parse, terms;
      parse = (function() {
        var ref;
        switch ((ref = this._options) != null ? ref.type : void 0) {
          case "integer":
          case "date":
            return function(s) {
              return parseInt(s);
            };
          case "float":
            return function(s) {
              return parseFloat(s);
            };
          case "boolean":
            return function(s) {
              return (s != null ? s.toLowerCase().trim() : void 0) === "true";
            };
          default:
            return function(s) {
              return s;
            };
        }
      }).call(this);
      terms = {};
      terms[this.field] = (paramString.split(',')).map(parse);
      return {
        terms: terms
      };
    }

    interpreteAggResult(aggBody) {
      var bucket, buckets, i, len, ref;
      buckets = {};
      ref = aggBody.buckets;
      for (i = 0, len = ref.length; i < len; i++) {
        bucket = ref[i];
        buckets[bucket.key] = bucket.doc_count;
      }
      return buckets;
    }

  };

}).call(this);
