"""Types for extracting data from HTML documents."""

import dataclasses
from typing import NewType

Attribute = NewType("Attribute", str)
Selector = NewType("Selector", str)


@dataclasses.dataclass(frozen=True)
class FieldFilter:
    """A single filter step in a field's filter chain."""

    name: str
    args: list[str] = dataclasses.field(default_factory=list)


@dataclasses.dataclass(frozen=True)
class Field:
    """Selector definition to extract a value from an HTML document."""

    selector: Selector
    attribute: Attribute | None = None
    remove: Selector | None = None
    filters: list[FieldFilter] = dataclasses.field(default_factory=list)


@dataclasses.dataclass(frozen=True)
class SearchFields:
    """Search field definitions for an HTML-based tracker."""

    title: Field
    size: Field
    date: Field
    seeders: Field
    leechers: Field
    magnet: Field | None = None
    download: Field | None = None
    details: Field | None = None
