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

available_balance: {
        type: DataTypes.DECIMAL,
      
      

      },

lifetime_earned: {
        type: DataTypes.DECIMAL,
      
      

      },

lifetime_spent: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

payouts_enabled: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  demo_wallets.associate = (db) => {


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


































    db.demo_wallets.hasMany(db.wallet_transactions, {
      as: 'wallet_transactions_wallet',
      foreignKey: {
          name: 'walletId',
      },
      constraints: false,
    });



//end loop



    db.demo_wallets.belongsTo(db.users, {
      as: 'owner_user',
      foreignKey: {
        name: 'owner_userId',
      },
      constraints: false,
    });

    db.demo_wallets.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return demo_wallets;
};


