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

sample_request_number: {
        type: DataTypes.TEXT,
      
      

      },

sample_quantity: {
        type: DataTypes.INTEGER,
      
      

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

needed_by: {
        type: DataTypes.DATE,
      
      

      },

sample_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"requested",


"approved",


"shipped",


"delivered",


"declined",


"cancelled"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  sample_requests.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.sample_requests.belongsTo(db.accounts, {
      as: 'account',
      foreignKey: {
        name: 'accountId',
      },
      constraints: false,
    });

    db.sample_requests.belongsTo(db.locations, {
      as: 'location',
      foreignKey: {
        name: 'locationId',
      },
      constraints: false,
    });

    db.sample_requests.belongsTo(db.users, {
      as: 'requested_by',
      foreignKey: {
        name: 'requested_byId',
      },
      constraints: false,
    });

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




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

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



  return sample_requests;
};


