"""
Coverage tests for merkle_path.py - untested branches.
"""

import pytest

from bsv.merkle_path import MerklePath

# ========================================================================
# MerklePath initialization branches
# ========================================================================


def test_merkle_path_init_empty():
    """Test MerklePath with empty path."""
    mp = MerklePath(block_height=0, path=[])
    assert mp.block_height == 0
    assert len(mp.path) == 0


def test_merkle_path_init_with_path():
    """Test MerklePath with path data."""
    path = [{"offset": 0, "hash": "00" * 32}, {"offset": 1, "hash": "11" * 32}]
    mp = MerklePath(block_height=100, path=path)
    assert mp.block_height == 100
    assert len(mp.path) == 2


def test_merkle_path_init_with_txid():
    """Test MerklePath with txid."""
    mp = MerklePath(block_height=100, path=[], txid="abc123")
    assert mp.txid == "abc123"


# ========================================================================
# MerklePath methods
# ========================================================================


def test_merkle_path_to_dict():
    """Test MerklePath to_dict."""
    path = [{"offset": 0, "hash": "00" * 32}]
    mp = MerklePath(block_height=100, path=path)
    result = mp.to_dict()
    assert isinstance(result, dict)
    assert "blockHeight" in result or "block_height" in result


def test_merkle_path_from_dict():
    """Test MerklePath from_dict."""
    data = {"blockHeight": 100, "path": [{"offset": 0, "hash": "00" * 32}]}
    mp = MerklePath.from_dict(data)
    assert mp.block_height == 100


def test_merkle_path_compute_root_empty():
    """Test compute_root with empty path."""
    mp = MerklePath(block_height=0, path=[])
    try:
        root = mp.compute_root(b"\x00" * 32)
        assert isinstance(root, bytes) or root is None
    except Exception:
        # May require valid path
        pass


def test_merkle_path_verify():
    """Test merkle path verification."""
    mp = MerklePath(block_height=0, path=[])
    try:
        is_valid = mp.verify(b"\x00" * 32, b"\x00" * 32)
        assert isinstance(is_valid, bool)
    except AttributeError:
        # May not have verify method
        pass


# ========================================================================
# Edge cases
# ========================================================================


def test_merkle_path_with_large_height():
    """Test MerklePath with large block height."""
    mp = MerklePath(block_height=999999, path=[])
    assert mp.block_height == 999999


def test_merkle_path_with_negative_height():
    """Test MerklePath with negative height."""
    try:
        mp = MerklePath(block_height=-1, path=[])
        assert mp.block_height == -1
    except ValueError:
        # May validate height
        pass


def test_merkle_path_with_none_path():
    """Test MerklePath with None path."""
    try:
        mp = MerklePath(block_height=0, path=None)
        assert mp.path is None or mp.path == []
    except TypeError:
        # May require list
        pass


def test_merkle_path_str_representation():
    """Test MerklePath string representation."""
    mp = MerklePath(block_height=100, path=[])
    str_repr = str(mp)
    assert isinstance(str_repr, str)
