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

supplier_item_code: {
        type: DataTypes.TEXT,
      
      

      },

lead_time_days: {
        type: DataTypes.INTEGER,
      
      

      },

last_price: {
        type: DataTypes.DECIMAL,
      
      

      },

preferred: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  approved_vendors.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.approved_vendors.belongsTo(db.items, {
      as: 'item',
      foreignKey: {
        name: 'itemId',
      },
      constraints: false,
    });

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




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

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



  return approved_vendors;
};


