const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const loyalty_accounts = sequelize.define(
    'loyalty_accounts',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

points_balance: {
        type: DataTypes.INTEGER,
      
      

      },

last_activity_at: {
        type: DataTypes.DATE,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  loyalty_accounts.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity




















    db.loyalty_accounts.hasMany(db.loyalty_transactions, {
      as: 'loyalty_transactions_loyalty_account',
      foreignKey: {
          name: 'loyalty_accountId',
      },
      constraints: false,
    });










//end loop



    db.loyalty_accounts.belongsTo(db.users, {
      as: 'client_user',
      foreignKey: {
        name: 'client_userId',
      },
      constraints: false,
    });




    db.loyalty_accounts.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.loyalty_accounts.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return loyalty_accounts;
};


