from dataclasses import dataclass

import httpx

from .base import AbuseResponse, json_data


@dataclass(frozen=True, slots=True, kw_only=True)
class ReportResponse(AbuseResponse):
    ip_address: str
    abuse_confidence_score: int

    @classmethod
    def from_response(cls, response: httpx.Response) -> "ReportResponse":
        data = json_data(response)
        return cls(
            **cls.metadata(response),
            ip_address=data["ipAddress"],
            abuse_confidence_score=data["abuseConfidenceScore"],
        )


@dataclass(frozen=True, slots=True, kw_only=True)
class ClearAddressResponse(AbuseResponse):
    num_reports_deleted: int

    @classmethod
    def from_response(cls, response: httpx.Response) -> "ClearAddressResponse":
        data = json_data(response)
        return cls(**cls.metadata(response), num_reports_deleted=data["numReportsDeleted"])
