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

check_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"sanctions",


"financial_health",


"references",


"legal_documents",


"site_visit"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"passed",


"failed"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

checked_at: {
        type: DataTypes.DATE,
      
      

      },

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

  supplier_diligence_checks.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.supplier_diligence_checks.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.supplier_diligence_checks.belongsTo(db.suppliers, {
      as: 'supplier',
      foreignKey: {
        name: 'supplierId',
      },
      constraints: false,
    });

    db.supplier_diligence_checks.belongsTo(db.users, {
      as: 'checked_by',
      foreignKey: {
        name: 'checked_byId',
      },
      constraints: false,
    });

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



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


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

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



  return supplier_diligence_checks;
};


