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

name: {
        type: DataTypes.TEXT,
      
      

      },

shelf_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"aisle",


"endcap",


"fridge",


"freezer",


"checkout_rack",


"bulk_bin"

        ],

      },

capacity_units: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  shelves.associate = (db) => {


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





























    db.shelves.hasMany(db.shelf_slots, {
      as: 'shelf_slots_shelf',
      foreignKey: {
          name: 'shelfId',
      },
      constraints: false,
    });























//end loop



    db.shelves.belongsTo(db.market_stores, {
      as: 'store',
      foreignKey: {
        name: 'storeId',
      },
      constraints: false,
    });

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




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

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



  return shelves;
};


