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

credential_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"education",


"certificate",


"portfolio",


"work_experience",


"license"

        ],

      },

title_text: {
        type: DataTypes.TEXT,
      
      

      },

issuer_name: {
        type: DataTypes.TEXT,
      
      

      },

issued_at: {
        type: DataTypes.DATE,
      
      

      },

valid_until: {
        type: DataTypes.DATE,
      
      

      },

verification_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"unverified",


"pending",


"verified",


"rejected"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  user_credentials.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_credentials.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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



    db.user_credentials.hasMany(db.file, {
      as: 'proof_files',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.user_credentials.getTableName(),
        belongsToColumn: 'proof_files',
      },
    });


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

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



  return user_credentials;
};


