"""Tests for the shared HTTP timeout helper."""

from __future__ import annotations

from media_library_viewer_api.clients.http_timeout import (
    DEFAULT_CONNECT_TIMEOUT,
    DEFAULT_READ_TIMEOUT,
    http_timeout,
)


class TestHttpTimeout:
    def test_http_timeout_returns_tuple(self) -> None:
        result = http_timeout(30)
        assert result == (DEFAULT_CONNECT_TIMEOUT, 30.0)

    def test_http_timeout_default_when_none(self) -> None:
        result = http_timeout(None)
        assert result == (DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT)

    def test_http_timeout_default_when_zero(self) -> None:
        result = http_timeout(0)
        assert result == (DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT)

    def test_http_timeout_custom_connect(self) -> None:
        result = http_timeout(30, connect_timeout=10)
        assert result == (10.0, 30.0)

    def test_http_timeout_default_when_negative(self) -> None:
        result = http_timeout(-5)
        assert result == (DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT)

    def test_http_timeout_default_when_garbage_string(self) -> None:
        result = http_timeout("garbage")  # type: ignore[arg-type]
        assert result == (DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT)

    def test_http_timeout_accepts_int(self) -> None:
        result = http_timeout(45)
        assert result == (5.0, 45.0)
