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

location_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"cuisine",


"bar",


"entretien"

        ],

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  stock_locations.associate = (db) => {


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
























    db.stock_locations.hasMany(db.stock_items, {
      as: 'stock_items_stock_location',
      foreignKey: {
          name: 'stock_locationId',
      },
      constraints: false,
    });






//end loop



    db.stock_locations.belongsTo(db.restaurants, {
      as: 'restaurant',
      foreignKey: {
        name: 'restaurantId',
      },
      constraints: false,
    });




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

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



  return stock_locations;
};


