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

score: {
        type: DataTypes.DECIMAL,
      
      

      },

comment: {
        type: DataTypes.TEXT,
      
      

      },

scored_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.offer_scores.belongsTo(db.supplier_offers, {
      as: 'supplier_offer',
      foreignKey: {
        name: 'supplier_offerId',
      },
      constraints: false,
    });

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

    db.offer_scores.belongsTo(db.users, {
      as: 'scored_by',
      foreignKey: {
        name: 'scored_byId',
      },
      constraints: false,
    });

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




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

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



  return offer_scores;
};


