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,
      },

plan_name: {
        type: DataTypes.TEXT,
      
      

      },

plan_description: {
        type: DataTypes.TEXT,
      
      

      },

billing_interval: {
        type: DataTypes.ENUM,
      
      

        values: [

"month",


"year",


"one_time"

        ],

      },

price_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

stripe_product_ref: {
        type: DataTypes.TEXT,
      
      

      },

stripe_price_ref: {
        type: DataTypes.TEXT,
      
      

      },

is_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.memberships, {
      as: '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;
};


