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

supplier_sku: {
        type: DataTypes.TEXT,
      
      

      },

last_price: {
        type: DataTypes.DECIMAL,
      
      

      },

last_price_at: {
        type: DataTypes.DATE,
      
      

      },

lead_time_days: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  supplier_products.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_products.belongsTo(db.suppliers, {
      as: 'supplier',
      foreignKey: {
        name: 'supplierId',
      },
      constraints: false,
    });

    db.supplier_products.belongsTo(db.products, {
      as: 'product',
      foreignKey: {
        name: 'productId',
      },
      constraints: false,
    });

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




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

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



  return supplier_products;
};


