from dataclasses import dataclass

import httpx

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


@dataclass(frozen=True, slots=True, kw_only=True)
class BulkReportResponse(AbuseResponse):
    saved_reports: int
    invalid_reports: tuple[BulkInvalidReport, ...]

    @classmethod
    def from_response(cls, response: httpx.Response) -> "BulkReportResponse":
        data = json_data(response)
        return cls(
            **cls.metadata(response),
            saved_reports=data["savedReports"],
            invalid_reports=tuple(
                BulkInvalidReport.from_dict(item) for item in data.get("invalidReports", [])
            ),
        )
