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

evidence_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"LICENSE",


"INSURANCE",


"BUSINESS_REGISTRATION",


"INVOICE_REDACTED",


"BEFORE_PHOTO",


"AFTER_PHOTO",


"JOB_PROOF",


"OTHER"

        ],

      },

url: {
        type: DataTypes.TEXT,
      
      

      },

created_at_ts: {
        type: DataTypes.DATE,
      
      

      },

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

  verification_evidences.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.verification_evidences.belongsTo(db.verification_submissions, {
      as: 'submission',
      foreignKey: {
        name: 'submissionId',
      },
      constraints: false,
    });



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


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

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



  return verification_evidences;
};


