package com.faviotorres.pariaguas.utils;

import com.faviotorres.pariaguas.Constants;
import com.faviotorres.pariaguas.R;
import com.faviotorres.pariaguas.model.TempColor;

public class TemperatureUtils {

    private static final float KELVIN = 273.15F;

    private int getCelsiusFromKelvin(double kelvin){
        double celsius = kelvin - KELVIN;
        return (int) Math.round(celsius);
    }

    private int getFahrenheitFromKelvin(double kelvin){
        return (int)(((kelvin - KELVIN) * 9d/5) + 32);
    }

    private String getCelsiusFromKelvinAsString(double kelvin){
        return getCelsiusFromKelvin(kelvin)+"°C";
    }

    private String getFahrenheitFromKelvinAsString(double kelvin){
        return getFahrenheitFromKelvin(kelvin)+"°F";
    }

    public String getTemperature(int units, double kelvin){
        if(units == 0){
            return getCelsiusFromKelvinAsString(kelvin);
        }
        return getFahrenheitFromKelvinAsString(kelvin);
    }

    public TempColor getColorByIcon(String id) {
        return Constants.getToolbarColor(id);
    }

    public TempColor getColorByKelvin(double kelvin) {
        if (kelvin >= 305) {
            return new TempColor(0xfff44336, R.color.md_red_500, R.color.md_red_700);
        }
        return new TempColor(0xff64b5f6, R.color.md_blue_300, R.color.md_blue_500);
    }
}
