"""
TemperatureUnitConverter
Generated by Eden via recursive self-improvement
2025-10-27 18:34:53.653606
"""

class TemperatureUnitConverter:
    """
    Converts temperature values between different units (Fahrenheit, Celsius, Kelvin).
    The class takes an initial temperature value and its unit, then can convert it to any other supported unit.
    
    Methods:
        __init__(value: float, current_unit: str): Initializes with a temperature value and its unit.
        _from_fahrenheit(f_value: float) -> float: Helper method to get the value in Fahrenheit.
        _from_celsius(c_value: float) -> float: Helper method to get the value in Celsius.
        _from_kelvin(k_value: float) -> float: Helper method to get the value in Kelvin.
        convert_to(target_unit: str) -> float: Converts the temperature to the target unit and returns it.
    """
    
    def __init__(self, value: float, current_unit: str):
        self.value = value
        self.current_unit = current_unit.upper()
        
        if self.current_unit not in ['F', 'C', 'K']:
            raise ValueError("Unsupported temperature unit. Supported units are F, C, K.")
    
    def _from_fahrenheit(self) -> float:
        """Converts the stored value from Fahrenheit to Celsius."""
        return (self.value - 32) * 5/9
    
    def _from_celsius(self) -> float:
        """Converts the stored value from Celsius to Fahrenheit."""
        return self.value * 9/5 + 32
    
    def _from_kelvin(self) -> float:
        """Converts the stored value from Kelvin to Celsius."""
        return self.value - 273.15
    
    def convert_to(self, target_unit: str) -> float:
        """
        Converts the temperature from its current unit to the target unit.
        
        Args:
            target_unit (str): Target temperature unit (can be 'F', 'C', or 'K').
            
        Returns:
            float: Temperature value in the target unit.
            
        Raises:
            ValueError: If target_unit is not supported.
        """
        target_unit = target_unit.upper()
        if target_unit == self.current_unit:
            return self.value
        
        if self.current_unit == 'F':
            celsius_value = self._from_fahrenheit()
        elif self.current_unit == 'C':
            celsius_value = self.value
        else:  # 'K'
            celsius_value = self._from_kelvin()
        
        if target_unit == 'C':
            return celsius_value
        elif target_unit == 'F':
            return celsius_value * 9/5 + 32
        elif target_unit == 'K':
            return celsius_value + 273.15
        
        raise ValueError("Unsupported target temperature unit.")
# Convert 32 degrees Fahrenheit to Celsius
converter = TemperatureUnitConverter(32, 'F')
celsius_value = converter.convert_to('C')  # Returns 0

# Convert 0 degrees Celsius to Kelvin
converter2 = TemperatureUnitConverter(0, 'C')
kelvin_value = converter2.convert_to('K')  # Returns 273.15

# Convert 273.15 Kelvin to Fahrenheit
converter3 = TemperatureUnitConverter(273.15, 'K')
fahrenheit_value = converter3.convert_to('F')  # Returns 32