#include <Settings/Settings.hpp>
#include <Utilities/TemperatureScale.hpp>
#include <Utilities/Utilities.hpp>

std::string formatTemperature(int kelvin, TemperatureScale scale)
{
    switch (scale)
    {
    case TemperatureScale::Kelvin:
        return formatString("$+ K", kelvin);
    case TemperatureScale::Celsius:
        return formatString("$+ °C", kelvin - 273);
    case TemperatureScale::Fahrenheit:
        {
            float f = ((float) kelvin - 273.15) * (9.0f/5.0f) + 32.0f;
            return formatString("$+ °F", std::round(f));
        }
    default:
        crash("Invalid case.");
    }
}

std::string formatTemperature(int kelvin)
{
    return formatTemperature(kelvin, settings.preferredTemperatureScale);
}

std::string getTemperatureScaleEnumName(TemperatureScale scale)
{
    switch (scale)
    {
    case TemperatureScale::Kelvin: return "K";
    case TemperatureScale::Celsius: return "C";
    case TemperatureScale::Fahrenheit: return "F";
    default: crash("Invalid case.");
    }
}

TemperatureScale getTemperatureScaleByEnumName(const std::string &enumName)
{
    if (enumName == "K")
    {
        return TemperatureScale::Kelvin;
    }
    else if (enumName == "F")
    {
        return TemperatureScale::Fahrenheit;
    }
    else
    {
        return TemperatureScale::Celsius;
    }
}