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

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"core",


"external"

        ],

      },

node_index: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  skill_nodes.associate = (db) => {


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









    db.skill_nodes.hasMany(db.user_skill_node_awards, {
      as: 'user_skill_node_awards_skill_node',
      foreignKey: {
          name: 'skill_nodeId',
      },
      constraints: false,
    });

























//end loop



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




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

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



  return skill_nodes;
};


