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_transactions = sequelize.define(
    'loyalty_transactions',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

transaction_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"gain",


"utilisation",


"ajustement"

        ],

      },

points: {
        type: DataTypes.INTEGER,
      
      

      },

transaction_time: {
        type: DataTypes.DATE,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  loyalty_transactions.associate = (db) => {


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





























//end loop



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

    db.loyalty_transactions.belongsTo(db.payments, {
      as: 'payment',
      foreignKey: {
        name: 'paymentId',
      },
      constraints: false,
    });




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

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



  return loyalty_transactions;
};


