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

source_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"course_phase",


"lesson_task",


"github",


"reddit",


"marketplace",


"manual",


"admin"

        ],

      },

source_label: {
        type: DataTypes.TEXT,
      
      

      },

evidence_url: {
        type: DataTypes.TEXT,
      
      

      },

confidence_score: {
        type: DataTypes.DECIMAL,
      
      

      },

awarded_at: {
        type: DataTypes.DATE,
      
      

      },

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

  user_skill_node_awards.associate = (db) => {


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

































//end loop



    db.user_skill_node_awards.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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

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




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

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



  return user_skill_node_awards;
};


