"""HUNT (Discovery) schemas."""

from __future__ import annotations

from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field


class HuntSniperItem(BaseModel):
    domain: str
    platform: str
    auction_url: str
    current_bid: float
    currency: str
    end_time: datetime
    age_years: Optional[int] = None
    backlinks: Optional[int] = None
    pounce_score: Optional[int] = None


class HuntSniperResponse(BaseModel):
    items: list[HuntSniperItem]
    total: int
    filtered_out_missing_data: int = 0
    last_updated: Optional[datetime] = None


class TrendItem(BaseModel):
    title: str
    approx_traffic: Optional[str] = None
    published_at: Optional[datetime] = None
    link: Optional[str] = None


class TrendsResponse(BaseModel):
    geo: str = "US"
    items: list[TrendItem]
    fetched_at: datetime


class KeywordAvailabilityRequest(BaseModel):
    keywords: list[str] = Field(min_length=1, max_length=25)
    tlds: list[str] = Field(default_factory=lambda: ["com", "io", "ai", "net", "org"], max_length=20)


class KeywordAvailabilityRow(BaseModel):
    keyword: str
    domain: str
    tld: str
    is_available: Optional[bool] = None
    status: str  # available|taken|unknown


class KeywordAvailabilityResponse(BaseModel):
    items: list[KeywordAvailabilityRow]


class TypoCheckRequest(BaseModel):
    brand: str = Field(min_length=2, max_length=50)
    tlds: list[str] = Field(default_factory=lambda: ["com"], max_length=10)
    limit: int = Field(default=50, ge=1, le=200)


class TypoCandidate(BaseModel):
    domain: str
    is_available: Optional[bool] = None
    status: str  # available|taken|unknown


class TypoCheckResponse(BaseModel):
    brand: str
    items: list[TypoCandidate]


class BrandableRequest(BaseModel):
    pattern: str = Field(description="cvcvc|cvccv|human", examples=["cvcvc"])
    tlds: list[str] = Field(default_factory=lambda: ["com"], max_length=10)
    limit: int = Field(default=30, ge=1, le=100)
    max_checks: int = Field(default=400, ge=50, le=2000)


class BrandableCandidate(BaseModel):
    domain: str
    is_available: Optional[bool] = None
    status: str  # available|taken|unknown


class BrandableResponse(BaseModel):
    pattern: str
    items: list[BrandableCandidate]

