"""Data models for acsearch.info auction records."""

from dataclasses import dataclass, field, asdict
from typing import Optional


@dataclass
class AuctionInfo:
    """Auction house and sale metadata."""
    house: str = ""
    sale: str = ""
    date: str = ""
    lot_number: str = ""


@dataclass
class PriceInfo:
    """Price information for a lot."""
    currency: str = ""
    estimate: str = ""       # e.g. "CHF 500"
    estimate_low: float = 0.0
    estimate_high: float = 0.0
    realized: str = ""        # e.g. "CHF 650"
    realized_numeric: float = 0.0
    hammer: str = ""          # hammer price before premium


@dataclass
class CoinSpecs:
    """Physical specifications of a coin."""
    weight: str = ""       # e.g. "14.26g"
    diameter: str = ""     # e.g. "25 mm"
    die_axis: str = ""     # e.g. "12h"
    metal: str = ""        # AR, AV, AE, etc.
    denomination: str = "" # Tetradrachm, Denarius, etc.


@dataclass
class ImageInfo:
    """Image reference for a lot."""
    url: str = ""
    thumbnail: str = ""
    caption: str = ""


@dataclass
class LotReference:
    """Bibliographic reference for a coin (SNG, Le Rider, etc.)."""
    source: str = ""       # e.g. "Le Rider"
    number: str = ""       # e.g. "525 (D231/R358)"
    full: str = ""         # e.g. "Le Rider-437 (D231/R358)"


@dataclass
class ProvenanceEntry:
    """Previous ownership/sale history."""
    text: str = ""
    type: str = ""         # "ex-collection", "ex-auction", "pedigree"


@dataclass
class SearchResult:
    """A single search result (summary view)."""
    id: str = ""
    title: str = ""
    description: str = ""
    auction: AuctionInfo = field(default_factory=AuctionInfo)
    price: PriceInfo = field(default_factory=PriceInfo)
    specs: CoinSpecs = field(default_factory=CoinSpecs)
    images: list[ImageInfo] = field(default_factory=list)
    references: list[LotReference] = field(default_factory=list)
    url: str = ""


@dataclass
class LotDetail:
    """Full lot detail including extended description, provenance, etc."""
    id: str = ""
    title: str = ""
    description: str = ""          # full catalog description
    obverse_legend: str = ""
    reverse_legend: str = ""
    auction: AuctionInfo = field(default_factory=AuctionInfo)
    price: PriceInfo = field(default_factory=PriceInfo)
    specs: CoinSpecs = field(default_factory=CoinSpecs)
    images: list[ImageInfo] = field(default_factory=list)
    references: list[LotReference] = field(default_factory=list)
    provenance: list[ProvenanceEntry] = field(default_factory=list)
    grade: str = ""
    notes: str = ""                 # auction house notes
    url: str = ""


@dataclass
class SearchResponse:
    """Response from a search query."""
    query: str = ""
    total_results: int = 0
    page: int = 1
    results_per_page: int = 100
    time_seconds: float = 0.0
    results: list[SearchResult] = field(default_factory=list)
