/**
 * @file box.cpp
 * @author Jan Holáň, xholan11 (xholan11@vutbr.cz)
 * @brief translated with gcc version 12.2.1
 * @version 0.1
 * @date 2023-05-01
 * 
 * @copyright Copyright (c) 2023
 * 
 */

#include "WarehousePickingOpt.h"

Box::Box(float _width, float _height, float _depth, float _max_weight, string _name, float _usable_capacity_percentage)
    : width(_width),
      height(_height),
      depth(_depth),
      max_weight(_max_weight),
      name(_name),
      usable_capacity_percentage(_usable_capacity_percentage)
{
    // compute capacity volume of the box
    this->capacity = width * height * depth * usable_capacity_percentage;
    this->free_capacity = this->capacity;
    this->used_capacity = 0;
}

Box::~Box() {}

float Box::getCapacity()
{
    return this->capacity;
}
float Box::getFreeCapacity()
{
    return this->free_capacity;
}
float Box::getUsedCapacity()
{
    return this->used_capacity;
}

map<int, BoxItem> Box::getItemsInTheBox()
{
    return this->product_boxitem_map;
}

bool Box::isEmpty()
{
    return this->used_capacity == 0.0;
}
bool Box::addItem(BoxItem &boxItem)
{
    if (this->product_boxitem_map.find(boxItem.order_item.Product) != this->product_boxitem_map.end())
    {
        // if the item is already registered in the map
        // just increase the number of them by the count of units in boxItem
        this->product_boxitem_map.at(boxItem.order_item.Product).countUnitsUp(boxItem.item_specification.ContentQty);
    }
    else
    {
        // add the boxitem to the map
        this->product_boxitem_map.insert({boxItem.order_item.Product, boxItem});
    }
    // just increase or decrease the capacities
    this->free_capacity -= boxItem.item_specification.Volume;
    this->used_capacity += boxItem.item_specification.Volume;
    return true;
}