# person_step09.py
#
# ICS 33 Spring 2026
# Code Example
#
# An implementation of our Person class that uses properties to establish the
# immutability of the name and birthdate attributes.


class Person:

    # We'll initialize a Person by storing name and birthdate into protected
    # attributes.
    def __init__(self, name, birthdate):
        self._name = name
        self._birthdate = birthdate


    # The name and birthdate methods here will become properties, which means
    # we'll be able to access them as though they were (in this case, read-only)
    # attributes.
    @property
    def name(self):
        return self._name


    @property
    def birthdate(self):
        return self._birthdate


    # Nothing needed to change below here.


    def __eq__(self, other):
        return isinstance(other, Person) and \
               (self.name, self.birthdate) == (other.name == other.birthdate)


    def __hash__(self):
        return hash((self.name, self.birthdate))


    def age(self, as_of_date):
        if self.birthdate > as_of_date:
            raise ValueError(f'Person was not born yet on {as_of_date}')

        years_old = as_of_date.year - self.birthdate.year

        if (self.birthdate.month, self.birthdate.day) >= (as_of_date.month, as_of_date.day):
            years_old -= 1

        return years_old
