/**
 * @file warehouse.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"

#include "waddress_functions.hpp"

Warehouse::Warehouse() {}

Warehouse::~Warehouse() {}

int Warehouse::getDistanceBetweenAddresses(SECTOR_ADDR_T first_addr, SECTOR_ADDR_T second_addr)
{
    //* WARNING - this serves as setup for the method of how to compute addresses
    using namespace ver2::measuring;

    int result = 0;
    string first_sec = first_addr.section;
    string second_sec = second_addr.section;

    if ((first_sec[0] == second_sec[0] && first_sec[1] != 'P' && second_sec[1] != 'P') || (first_sec[1] == 'P' && second_sec[1] == 'P'))
    {
        // cout << "same" << endl;
        if (strncmp(first_sec.c_str(), "GP", 2) == 0)
            result = getDistanceInSectorGP(first_addr, second_addr);
        else if (first_sec[0] == 'G')
            result = getDistanceInSectorG(first_addr, second_addr);
        else if (first_sec[0] == 'V')
            result = getDistanceInSectorV(first_addr, second_addr);
        else if (first_sec[0] == 'P')
            result = getDistanceInSectorP(first_addr, second_addr);
    }
    else
    {
        // addresses are different so count distance between two sectors

        if ((first_sec[0] == 'P' && second_sec.substr(0, 2) == "GP") ||
            (first_sec.substr(0, 2) == "GP" && second_sec[0] == 'P'))
        {
            // between P and GP
            // cout << "P and GP" << endl;
            result = getDistanceBetweenSectors_GP_P(first_addr, second_addr);
        }
        else if ((first_sec[0] == 'V' && second_sec.substr(0, 2) == "GP") ||
                 (first_sec.substr(0, 2) == "GP" && second_sec[0] == 'V'))
        {
            // between V and GP
            // cout << "V and GP" << endl;
            result = getDistanceBetweenSectors_V_GP(first_addr, second_addr);
        }
        else if ((first_sec[0] == 'G' && second_sec.substr(0, 2) == "GP") ||
                 (first_sec.substr(0, 2) == "GP" && second_sec[0] == 'G'))
        {
            // between G and GP
            // cout << "G and GP" << endl;
            result = getDistanceBetweenSectors_G_GP(first_addr, second_addr);
        }
        else if ((first_sec[0] == 'G' && second_sec[0] == 'V') ||
                 (first_sec[0] == 'V' && second_sec[0] == 'G'))
        {
            // between G and V
            // cout << "G and V" << endl;
            result = getDistanceBetweenSectors_G_V(first_addr, second_addr);
        }
        else if ((first_sec[0] == 'G' && second_sec[0] == 'P') ||
                 (first_sec[0] == 'P' && second_sec[0] == 'G'))
        {
            // between G and P
            // cout << "G and P" << endl;
            result = getDistanceBetweenSectors_G_P(first_addr, second_addr);
        }
        else if ((first_sec[0] == 'V' && second_sec[0] == 'P') ||
                 (first_sec[0] == 'P' && second_sec[0] == 'V'))
        {
            // between V and P
            // cout << "V and P" << endl;
            result = getDistanceBetweenSectors_V_P(first_addr, second_addr);
        }
    }

    return result;
}

int Warehouse::getDistanceBetweenAddresses(WAddress first_addr, WAddress second_addr)
{
    int a = Warehouse::getDistanceBetweenAddresses(first_addr.getWarehouseWAddress(), second_addr.getWarehouseWAddress());
    return a;
}
