"""Base entity for domain layer.

This module defines the base entity class that all domain entities inherit from.
"""

from datetime import datetime
from typing import Optional


class BaseEntity:
    """Base domain entity.
    
    All domain entities should inherit from this class.
    This is NOT a database model, but a pure domain object.
    
    Attributes:
        id: Entity identifier
        created_at: Creation timestamp
        updated_at: Last update timestamp
    """
    
    def __init__(
        self,
        id: Optional[int] = None,
        created_at: Optional[datetime] = None,
        updated_at: Optional[datetime] = None
    ):
        """Initialize base entity.
        
        Args:
            id: Entity identifier
            created_at: Creation timestamp
            updated_at: Last update timestamp
        """
        self.id = id
        self.created_at = created_at or datetime.utcnow()
        self.updated_at = updated_at or datetime.utcnow()
    
    def __eq__(self, other: object) -> bool:
        """Check equality based on ID.
        
        Args:
            other: Other object
            
        Returns:
            bool: True if same entity
        """
        if not isinstance(other, self.__class__):
            return False
        return self.id == other.id
    
    def __hash__(self) -> int:
        """Hash based on ID.
        
        Returns:
            int: Hash value
        """
        return hash(self.id)
    
    def __repr__(self) -> str:
        """String representation.
        
        Returns:
            str: String representation
        """
        return f"<{self.__class__.__name__}(id={self.id})>"

