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

key: {
        type: DataTypes.TEXT,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

route: {
        type: DataTypes.TEXT,
      
      

      },

parent_key: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  app_menus.associate = (db) => {


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










    db.app_menus.hasMany(db.role_permissions, {
      as: 'role_permissions_menu',
      foreignKey: {
          name: 'menuId',
      },
      constraints: false,
    });








































//end loop






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

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



  return app_menus;
};


