from whatsrb_cloud.errors import (
    WhatsrbCloudError,
    AuthenticationError,
    ForbiddenError,
    NotFoundError,
    ValidationError,
    ConflictError,
    ServerError,
    RateLimitError,
)


class TestErrorHierarchy:
    def test_base_error(self):
        err = WhatsrbCloudError("test", status=500, body={"error": "test"})
        assert str(err) == "test"
        assert err.status == 500
        assert err.body == {"error": "test"}

    def test_authentication_error(self):
        err = AuthenticationError("Unauthorized", status=401)
        assert isinstance(err, WhatsrbCloudError)
        assert err.status == 401

    def test_forbidden_error(self):
        err = ForbiddenError("Forbidden", status=403)
        assert isinstance(err, WhatsrbCloudError)

    def test_not_found_error(self):
        err = NotFoundError("Not found", status=404)
        assert isinstance(err, WhatsrbCloudError)

    def test_validation_error_details(self):
        err = ValidationError("Invalid", status=422, body={"details": {"name": ["is required"]}})
        assert err.details == {"name": ["is required"]}

    def test_validation_error_no_details(self):
        err = ValidationError("Invalid", status=422, body={})
        assert err.details == {}

    def test_validation_error_no_body(self):
        err = ValidationError("Invalid", status=422)
        assert err.details == {}

    def test_conflict_error(self):
        err = ConflictError("Conflict", status=409)
        assert isinstance(err, WhatsrbCloudError)

    def test_server_error(self):
        err = ServerError("Internal", status=500)
        assert isinstance(err, WhatsrbCloudError)

    def test_rate_limit_error(self):
        err = RateLimitError("Too many", status=429, retry_after=60)
        assert isinstance(err, WhatsrbCloudError)
        assert err.retry_after == 60
