# person_step04.py
#
# ICS 33 Spring 2026
# Code Example
#
# This module makes our Person objects immutable again, at the design cost of
# name and birthdate becoming methods instead of attributes.


class Person:
    def __init__(self, name, birthdate):
        self._name = name
        self._birthdate = birthdate


    def name(self):
        return self._name


    def birthdate(self):
        return 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


    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))
