// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
// for more of what you can do here.
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;

module.exports = function (app) {
  const sequelizeClient = app.get('sequelizeClient');
  const client = sequelizeClient.define('client', {
    createdAt: { 
      type: DataTypes.DATE,
      field: 'created_at'
    },
    updatedAt: {
      type: DataTypes.DATE,
      field: 'updated_at'
    },
    first_name: {
      type: DataTypes.CHAR,
    },
    last_name: {
      type: DataTypes.CHAR,
    },
    email: {
      type: DataTypes.CHAR,
    },
    is_active: {
      type: DataTypes.BOOLEAN,
    }
  }, {
    hooks: {
      beforeCount(options) {
        options.raw = true;
      }
    }
  });

  client.associate = function (models) { // eslint-disable-line no-unused-vars
    // Define associations here
    // See http://docs.sequelizejs.com/en/latest/docs/associations/
    client.hasMany(models.account, {foreignKey: 'client_id'});
  };

  return client;
};
