from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from .models import ESIRequest


class InvalidRequestError(Exception):
    """Incorrect request parameters being blocked."""

    def __init__(self, reson: str, value):
        self.reason = reson
        self.value = value
        self.msg = "Request blocked: invalid request parameter {reason}: {value}"

    def __str__(self):
        return self.msg.format(reason=self.reason, value=self.value)


class ESIResponseError(Exception):
    """Connection error during reading response, catch from aiohttp.ClientResponseError.

    request_info: instance of ESIRequest
    """
    def __init__(self, status: int, request_info: "ESIRequest", message: str):
        self.status = status
        self.request_info = request_info
        self.message = message

    def __str__(self) -> str:
        return "{}, message={!r}, url={!r}".format(
            self.status,
            self.message,
            self.request_info.real_url,
        )

class EndpointDownError(Exception):
    """Endpoint is not alive (red flag)."""

    def __init__(self, endpoint_key: str) -> None:
        self.key = endpoint_key

    def __str__(self) -> str:
        return f"Endpoint {self.key} is not available."
