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

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

price_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

billing_interval: {
        type: DataTypes.ENUM,
      
      

        values: [

"one_time",


"monthly",


"yearly"

        ],

      },

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

  pricing_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.pricing_plans.hasMany(db.subscriptions, {
      as: 'subscriptions_pricing_plan',
      foreignKey: {
          name: 'pricing_planId',
      },
      constraints: false,
    });


    db.pricing_plans.hasMany(db.payments, {
      as: 'payments_pricing_plan',
      foreignKey: {
          name: 'pricing_planId',
      },
      constraints: false,
    });






//end loop



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




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

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



  return pricing_plans;
};


