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

name: {
        type: DataTypes.TEXT,
      
      

      },

weight: {
        type: DataTypes.DECIMAL,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  bid_criteria.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity





















    db.bid_criteria.hasMany(db.offer_scores, {
      as: 'offer_scores_bid_criterion',
      foreignKey: {
          name: 'bid_criterionId',
      },
      constraints: false,
    });
















//end loop



    db.bid_criteria.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.bid_criteria.belongsTo(db.procurement_cases, {
      as: 'procurement_case',
      foreignKey: {
        name: 'procurement_caseId',
      },
      constraints: false,
    });

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




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

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



  return bid_criteria;
};


