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

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

message: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"completed",


"refunded",


"failed"

        ],

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

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

  tips.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.tips.belongsTo(db.tip_pages, {
      as: 'tip_page',
      foreignKey: {
        name: 'tip_pageId',
      },
      constraints: false,
    });

    db.tips.belongsTo(db.users, {
      as: 'from_user',
      foreignKey: {
        name: 'from_userId',
      },
      constraints: false,
    });

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




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

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



  return tips;
};


