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

name: {
        type: DataTypes.TEXT,
      
      

      },

tier: {
        type: DataTypes.ENUM,
      
      

        values: [

"FREE",


"SILVER",


"GOLD",


"PREMIUM"

        ],

      },

monthly_doodlecoins: {
        type: DataTypes.INTEGER,
      
      

      },

doodlecoin_multiplier: {
        type: DataTypes.DECIMAL,
      
      

      },

price_supercharged: {
        type: DataTypes.INTEGER,
      
      

      },

perks_summary: {
        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,
    },
  );

  membership_plans.associate = (db) => {


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













    db.membership_plans.hasMany(db.user_memberships, {
      as: 'user_memberships_membership_plan',
      foreignKey: {
          name: 'membership_planId',
      },
      constraints: false,
    });

















//end loop






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

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



  return membership_plans;
};


