from dataclasses import dataclass

import httpx

from .base import AbuseResponse, json_data
from .models import ReportInfo


@dataclass(frozen=True, slots=True, kw_only=True)
class ReportsPaginatedResponse(AbuseResponse):
    total: int
    page: int
    count: int
    per_page: int
    last_page: int
    next_page_url: str | None
    previous_page_url: str | None
    results: tuple[ReportInfo, ...]

    @classmethod
    def from_response(cls, response: httpx.Response) -> "ReportsPaginatedResponse":
        data = json_data(response)
        return cls(
            **cls.metadata(response),
            total=data["total"],
            page=data["page"],
            count=data["count"],
            per_page=data["perPage"],
            last_page=data["lastPage"],
            next_page_url=data.get("nextPageUrl"),
            previous_page_url=data.get("previousPageUrl"),
            results=tuple(ReportInfo.from_dict(item) for item in data["results"]),
        )
