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

delta: {
        type: DataTypes.INTEGER,
      
      

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

created_at_ts: {
        type: DataTypes.DATE,
      
      

      },

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

  trust_adjustments.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.trust_adjustments.belongsTo(db.businesses, {
      as: 'business',
      foreignKey: {
        name: 'businessId',
      },
      constraints: false,
    });

    db.trust_adjustments.belongsTo(db.users, {
      as: 'admin_user',
      foreignKey: {
        name: 'admin_userId',
      },
      constraints: false,
    });




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

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



  return trust_adjustments;
};


