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

document_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"resume",


"cover_letter",


"portfolio",


"other"

        ],

      },

document_name: {
        type: DataTypes.TEXT,
      
      

      },

extracted_text: {
        type: DataTypes.TEXT,
      
      

      },

uploaded_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

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



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


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

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



  return resume_documents;
};


