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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"not_started",


"pending",


"approved",


"rejected"

        ],

      },

document_type: {
        type: DataTypes.TEXT,
      
      

      },

full_name_on_document: {
        type: DataTypes.TEXT,
      
      

      },

document_number: {
        type: DataTypes.TEXT,
      
      

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

reviewed_at: {
        type: DataTypes.DATE,
      
      

      },

review_note: {
        type: DataTypes.TEXT,
      
      

      },

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

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



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


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

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



  return kyc_verifications;
};


