97 lines
2.6 KiB
Python
97 lines
2.6 KiB
Python
"""TV Show domain value objects."""
|
|
from dataclasses import dataclass
|
|
from enum import Enum
|
|
|
|
from ..shared.exceptions import ValidationError
|
|
|
|
|
|
class ShowStatus(Enum):
|
|
"""Status of a TV show - whether it's still airing or has ended."""
|
|
ONGOING = "ongoing"
|
|
ENDED = "ended"
|
|
UNKNOWN = "unknown"
|
|
|
|
@classmethod
|
|
def from_string(cls, status_str: str) -> "ShowStatus":
|
|
"""
|
|
Parse status from string.
|
|
|
|
Args:
|
|
status_str: Status string (e.g., "ongoing", "ended")
|
|
|
|
Returns:
|
|
ShowStatus enum value
|
|
"""
|
|
status_map = {
|
|
"ongoing": cls.ONGOING,
|
|
"ended": cls.ENDED,
|
|
}
|
|
return status_map.get(status_str.lower(), cls.UNKNOWN)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class SeasonNumber:
|
|
"""
|
|
Value object representing a season number.
|
|
|
|
Validates that the season number is valid (>= 0).
|
|
Season 0 is used for specials.
|
|
"""
|
|
value: int
|
|
|
|
def __post_init__(self):
|
|
"""Validate season number."""
|
|
if not isinstance(self.value, int):
|
|
raise ValidationError(f"Season number must be an integer, got {type(self.value)}")
|
|
|
|
if self.value < 0:
|
|
raise ValidationError(f"Season number cannot be negative: {self.value}")
|
|
|
|
# Reasonable upper limit
|
|
if self.value > 100:
|
|
raise ValidationError(f"Season number too high: {self.value}")
|
|
|
|
def is_special(self) -> bool:
|
|
"""Check if this is the specials season (season 0)."""
|
|
return self.value == 0
|
|
|
|
def __str__(self) -> str:
|
|
return str(self.value)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"SeasonNumber({self.value})"
|
|
|
|
def __int__(self) -> int:
|
|
return self.value
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class EpisodeNumber:
|
|
"""
|
|
Value object representing an episode number.
|
|
|
|
Validates that the episode number is valid (>= 1).
|
|
"""
|
|
value: int
|
|
|
|
def __post_init__(self):
|
|
"""Validate episode number."""
|
|
if not isinstance(self.value, int):
|
|
raise ValidationError(f"Episode number must be an integer, got {type(self.value)}")
|
|
|
|
if self.value < 1:
|
|
raise ValidationError(f"Episode number must be >= 1, got {self.value}")
|
|
|
|
# Reasonable upper limit
|
|
if self.value > 1000:
|
|
raise ValidationError(f"Episode number too high: {self.value}")
|
|
|
|
def __str__(self) -> str:
|
|
return str(self.value)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"EpisodeNumber({self.value})"
|
|
|
|
def __int__(self) -> int:
|
|
return self.value
|