"""Tests for SDK data types and exceptions."""

from quicproquo.types import (
    ConnectOptions,
    Envelope,
    ChannelResult,
    HealthInfo,
    QpqError,
    AuthError,
    TimeoutError,
    ConnectionError,
)


def test_connect_options_defaults():
    opts = ConnectOptions(addr="127.0.0.1:5001")
    assert opts.addr == "127.0.0.1:5001"
    assert opts.ca_cert_path == ""
    assert opts.insecure_skip_verify is False
    assert opts.connect_timeout_ms == 5_000
    assert opts.request_timeout_ms == 10_000


def test_envelope_immutable():
    env = Envelope(seq=1, data=b"hello")
    assert env.seq == 1
    assert env.data == b"hello"


def test_channel_result():
    cr = ChannelResult(channel_id=b"\x01", was_new=True)
    assert cr.was_new is True


def test_health_info():
    h = HealthInfo(status="ok", version="0.1.0", uptime_secs=42)
    assert h.status == "ok"
    assert h.uptime_secs == 42


def test_exception_hierarchy():
    assert issubclass(AuthError, QpqError)
    assert issubclass(TimeoutError, QpqError)
    assert issubclass(ConnectionError, QpqError)

    # Can catch all qpq errors with base class.
    try:
        raise AuthError("bad password")
    except QpqError as e:
        assert "bad password" in str(e)
