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

code: {
        type: DataTypes.TEXT,
      
      

      },

pin: {
        type: DataTypes.TEXT,
      
      

      },

amount_doodlecoins: {
        type: DataTypes.INTEGER,
      
      

      },

max_redemptions: {
        type: DataTypes.INTEGER,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

success_message: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  coin_codes.associate = (db) => {


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









    db.coin_codes.hasMany(db.coin_code_redemptions, {
      as: 'coin_code_redemptions_coin_code',
      foreignKey: {
          name: 'coin_codeId',
      },
      constraints: false,
    });





















//end loop






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

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



  return coin_codes;
};


