'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class Warehouse extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
      Warehouse.belongsTo(models.User, { as: 'manager', foreignKey: 'managerId' });
      // Warehouse.hasMany(models.StockAdjustment, { foreignKey: 'warehouseId' });
      // Warehouse.hasMany(models.StockTransfer, { foreignKey: 'fromWarehouseId' });
      // Warehouse.hasMany(models.StockTransfer, { foreignKey: 'toWarehouseId' });
      // Warehouse.hasMany(models.InventoryCount, { foreignKey: 'warehouseId' });
    }
  }
  Warehouse.init({
    code: DataTypes.STRING,
    name: DataTypes.STRING,
    type: DataTypes.STRING,
    managerId: DataTypes.INTEGER,
    email: DataTypes.STRING,
    phone: DataTypes.STRING,
    addressLine1: DataTypes.STRING,
    addressLine2: DataTypes.STRING,
    city: DataTypes.STRING,
    state: DataTypes.STRING,
    country: DataTypes.STRING,
    postalCode: DataTypes.STRING,
    latitude: DataTypes.DECIMAL,
    longitude: DataTypes.DECIMAL,
    capacity: DataTypes.INTEGER,
    currentUtilization: DataTypes.INTEGER,
    isActive: DataTypes.BOOLEAN,
    isPrimary: DataTypes.BOOLEAN,
    operatingHours: DataTypes.STRING,
    timezone: DataTypes.STRING,
    establishedDate: DataTypes.DATE,
    notes: DataTypes.TEXT
  }, {
    sequelize,
    modelName: 'Warehouse',
  });
  return Warehouse;
};