from __future__ import annotations

"""Author: Vasiliy Zdanovskiy
email: vasilyvz@gmail.com

Unit tests for mcp_proxy_adapter.transfer.errors.
"""

from mcp_proxy_adapter.transfer.errors import (
    TransferChecksumMismatchError,
    TransferError,
    TransferResumeConflictError,
)


def test_transfer_error_to_dict_contains_structured_fields() -> None:
    exc = TransferError(
        "base",
        transfer_id="tid",
        expected_offset=1,
        actual_offset=2,
        checksum_expected="aa",
        checksum_actual="bb",
        compression="gzip",
        phase="p",
    )
    d = exc.to_dict()
    assert d["exception_type"] == "TransferError"
    assert d["message"] == "base"
    assert d["transfer_id"] == "tid"
    assert d["expected_offset"] == 1
    assert d["actual_offset"] == 2
    assert d["checksum_expected"] == "aa"
    assert d["checksum_actual"] == "bb"
    assert d["compression"] == "gzip"
    assert d["phase"] == "p"


def test_resume_conflict_error_preserves_expected_and_actual_offsets() -> None:
    exc = TransferResumeConflictError(
        "m", transfer_id="t1", expected_offset=8, actual_offset=4
    )
    d = exc.to_dict()
    assert d["expected_offset"] == 8
    assert d["actual_offset"] == 4
    assert d["transfer_id"] == "t1"
    assert isinstance(exc, TransferResumeConflictError)


def test_checksum_mismatch_error_preserves_expected_and_actual_checksums() -> None:
    exc = TransferChecksumMismatchError(
        "bad",
        transfer_id="t2",
        checksum_expected="e" * 64,
        checksum_actual="a" * 64,
        phase="verify",
    )
    d = exc.to_dict()
    assert d["checksum_expected"] == "e" * 64
    assert d["checksum_actual"] == "a" * 64
    assert d["transfer_id"] == "t2"
