"""
Exercise 2: a Temperature class with a validated @property

Implement class Temperature with:
  __init__(self, celsius=0)
  celsius   -> @property, plain get/set of the underlying value
  fahrenheit -> @property (get AND set) that CONVERTS to/from celsius:
                  f = c * 9/5 + 32
                  c = (f - 32) * 5/9
  celsius setter must raise ValueError if the new value is below
  -273.15 (absolute zero).

Setting fahrenheit should update the SAME underlying celsius value
(there must only be one source of truth, not two independent fields).
"""

class Temperature:
    def __init__(self, celsius=0):
        # TODO
        pass

    @property
    def celsius(self):
        # TODO
        pass

    @celsius.setter
    def celsius(self, value):
        # TODO: validate >= -273.15
        pass

    @property
    def fahrenheit(self):
        # TODO
        pass

    @fahrenheit.setter
    def fahrenheit(self, value):
        # TODO: convert and delegate to the celsius setter/logic
        pass


# --- self-check: do not modify below this line ---
t = Temperature(0)
checks = [(t.fahrenheit, 32.0)]

t.fahrenheit = 212
checks.append((round(t.celsius, 5), 100.0))

t.celsius = 100
checks.append((t.fahrenheit, 212.0))

try:
    t.celsius = -300
    validation_raised = False
except ValueError:
    validation_raised = True
checks.append((validation_raised, True))

all_passed = all(actual == expected for actual, expected in checks)
for actual, expected in checks:
    print(f"got {actual!r}, expected {expected!r} -> {'PASS' if actual == expected else 'FAIL'}")

print("ALL PASS" if all_passed else "SOME FAILED")
