# person_step03.py
#
# ICS 33 Spring 2026
# Code Example
#
# This module replaces the namedtuple built in the previous version with a
# hand-written class whose objects have name and birthdate attributes, and
# that provide features that mirror many of the ones that our namedtuple had.


class Person:
    def __init__(self, name, birthdate):
        self.name = name
        self.birthdate = 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))
