"""Individual agent that extends the base Agent class with health-related attributes."""

import sys
from pathlib import Path
from typing import List

# Add framework src to path for imports
framework_src_path = Path(__file__).parent.parent.parent.parent / "src"
sys.path.insert(0, str(framework_src_path))

from layer1_core.entities.agent import Agent


class Individual(Agent):
    """
    An individual person in the simulation with health-related attributes.

    Individuals can be infected by disease agents (Infection instances).
    """

    def __init__(self, agent_id: str, age: int):
        """
        Initialize an Individual.

        Args:
            agent_id: Unique identifier for this individual
            age: Age of the individual in years
        """
        super().__init__(agent_id)
        self.age: int = age
        self.alive: bool = True
        self.infections: List['Infection'] = []  # List of Infection agents currently in this individual

    def add_infection(self, infection: 'Infection') -> None:
        """
        Add an infection to this individual.

        Args:
            infection: An Infection agent instance
        """
        self.infections.append(infection)

    def remove_infection(self, infection: 'Infection') -> None:
        """
        Remove an infection from this individual.

        Args:
            infection: An Infection agent instance to remove
        """
        if infection in self.infections:
            self.infections.remove(infection)

    def has_active_infection(self) -> bool:
        """Check if this individual has any active infections."""
        return len(self.infections) > 0

    def get_health_state(self) -> str:
        """
        Get the current health state of this individual.

        Returns:
            str: 'Dead', 'Infected', or 'Susceptible'
        """
        if not self.alive:
            return 'Dead'
        elif self.has_active_infection():
            return 'Infected'
        else:
            return 'Susceptible'

    def die(self) -> None:
        """Mark this individual as dead."""
        self.alive = False
        self.infections.clear()  # Clear infections when dead

    def __repr__(self):
        return f"Individual({self.agent_id}, age={self.age}, state={self.get_health_state()})"