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

bid_reference: {
        type: DataTypes.TEXT,
      
      

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

bid_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.ENUM,
      
      

        values: [

"CDF",


"USD"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"submitted",


"withdrawn",


"responsive",


"non_responsive",


"shortlisted",


"recommended",


"not_recommended"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  bids.associate = (db) => {


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


























    db.bids.hasMany(db.bid_evaluations, {
      as: 'bid_evaluations_bid',
      foreignKey: {
          name: 'bidId',
      },
      constraints: false,
    });


    db.bids.hasMany(db.awards, {
      as: 'awards_winning_bid',
      foreignKey: {
          name: 'winning_bidId',
      },
      constraints: false,
    });


























//end loop



    db.bids.belongsTo(db.tenders, {
      as: 'tender',
      foreignKey: {
        name: 'tenderId',
      },
      constraints: false,
    });

    db.bids.belongsTo(db.vendors, {
      as: 'vendor',
      foreignKey: {
        name: 'vendorId',
      },
      constraints: false,
    });

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




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

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



  return bids;
};


