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

name: {
        type: DataTypes.TEXT,
      
      

      },

plan_code: {
        type: DataTypes.ENUM,
      
      

        values: [

"basic",


"pro",


"label"

        ],

      },

price_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

price_currency: {
        type: DataTypes.TEXT,
      
      

      },

billing_period: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

features: {
        type: DataTypes.TEXT,
      
      

      },

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

  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.plans.hasMany(db.subscriptions, {
      as: 'subscriptions_plan',
      foreignKey: {
          name: 'planId',
      },
      constraints: false,
    });


































//end loop



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




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

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



  return plans;
};


