import dataclasses
import datetime as dt


@dataclasses.dataclass(frozen=True, order=False)
class Torrent:
    """A parsed torrent result from a tracker search."""

    name: str
    tracker: str
    magnet: str | None = None
    download: str | None = None
    details_url: str | None = None
    size: int = 0
    date: dt.datetime | None = None
    seeders: int = 0
    leechers: int = 0

    @property
    def filename(self) -> str:
        """Filename to use when saving the torrent."""
        if ".torrent" in self.name:
            return self.name
        return f"{self.name}.torrent"
