var base = require('../../lib/orm/base');
var utils = require('../../lib/orm/utils');

/**
 * Object representing a Service.
 * @constructor
 * @param {Object} attributes Attributes to set in the resulting object.
 */
var Service = function(attributes) {
  base.DBBase.call(this, Service, attributes);
};

/**
 * Add properties that help map to cassandra
 * complex types
 */
Service.meta = {
  name: 'Service',
  cname: 'service',
  columnFamily: 'objects',
  prefix: 'srv',
  dataPrefix: null,
  parents: [],
  indexes: {
    'session_idx': utils.addIndex(
      {
        key: ['session_id'],
        name: ['$ROWKEY', '$OBJKEY'],
        object: 'Service',
        columnFamily: 'session_to_service_idx' ,
        relationship: 'ScopedOneToMany'
      }),
    'tags_idx': utils.addIndex(
      {
        key: ['tags'],
        name: ['$ROWKEY', '$OBJKEY'],
        object: 'Service',
        columnFamily: 'tag_to_service_idx' ,
        relationship: 'ScopedOneToMany',
        _getKeys: function(bi, cleaned, meta) {
          var tags = cleaned.cols.tags || [];
          return tags;
        }
      })
  }
};

Service.fields = {
  'session_id': null,
  'metadata': {'default_value': {}},
  'tags': {'default_value': []}
};

Service.operationalVersion = 0;
base.inheritBase(Service, __filename);

exports.Service = Service;
