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

plan_name: {
        type: DataTypes.TEXT,
      
      

      },

plan_tier: {
        type: DataTypes.ENUM,
      
      

        values: [

"starter",


"professional",


"enterprise"

        ],

      },

price_monthly: {
        type: DataTypes.DECIMAL,
      
      

      },

price_yearly: {
        type: DataTypes.DECIMAL,
      
      

      },

max_users: {
        type: DataTypes.INTEGER,
      
      

      },

max_branches: {
        type: DataTypes.INTEGER,
      
      

      },

max_documents: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

      },

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

      },

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

  subscription_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.subscription_plans.hasMany(db.company_subscriptions, {
      as: 'company_subscriptions_plan',
      foreignKey: {
          name: 'planId',
      },
      constraints: false,
    });












//end loop



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




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

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



  return subscription_plans;
};


