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

document_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"rccm",


"tax_clearance",


"cnss",


"business_license",


"bank_letter",


"id",


"other"

        ],

      },

reference_number: {
        type: DataTypes.TEXT,
      
      

      },

issued_at: {
        type: DataTypes.DATE,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"valid",


"expiring",


"expired",


"rejected",


"pending_review"

        ],

      },

review_comment: {
        type: DataTypes.TEXT,
      
      

      },

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

  vendor_compliance_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.vendor_compliance_documents.belongsTo(db.vendors, {
      as: 'vendor',
      foreignKey: {
        name: 'vendorId',
      },
      constraints: false,
    });

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



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


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

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



  return vendor_compliance_documents;
};


