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

location_code: {
        type: DataTypes.TEXT,
      
      

      },

product_sku: {
        type: DataTypes.TEXT,
      
      

      },

quantity_on_hand: {
        type: DataTypes.DECIMAL,
      
      

      },

quantity_available: {
        type: DataTypes.DECIMAL,
      
      

      },

as_of: {
        type: DataTypes.DATE,
      
      

      },

source_reference: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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




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

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



  return availability_records;
};


