"""Phase 7 — tests for multi-view image-ref resolver helpers."""
from __future__ import annotations

import sys
from pathlib import Path
import pytest

_REPO_ROOT = Path(__file__).resolve().parents[4]
if str(_REPO_ROOT) not in sys.path:
    sys.path.insert(0, str(_REPO_ROOT))

from recoil.pipeline.tools.dispatch_cli import (  # noqa: E402
    _parse_image_refs_arg,
    _parse_image_paths_arg,
    _resolve_client_view,
    _VALID_VIEWS,
)


def test_parse_image_refs_legacy_form():
    result = _parse_image_refs_arg("JADE,WREN")
    assert result == [("JADE", "frontal"), ("WREN", "frontal")]


def test_parse_image_refs_view_tagged():
    result = _parse_image_refs_arg("JADE:three_quarter,WREN:profile")
    assert result == [("JADE", "three_quarter"), ("WREN", "profile")]


def test_parse_image_refs_unknown_view_raises():
    with pytest.raises(ValueError, match="unknown view"):
        _parse_image_refs_arg("JADE:nonexistent_view")


def test_parse_image_refs_empty():
    assert _parse_image_refs_arg("") == []


def test_parse_image_paths_valid(tmp_path):
    f = tmp_path / "test.png"
    f.write_bytes(b"fake")
    result = _parse_image_paths_arg(str(f), "tartarus")
    assert result == [f]


def test_parse_image_paths_missing_raises(tmp_path):
    with pytest.raises(FileNotFoundError):
        _parse_image_paths_arg(str(tmp_path / "nope.png"), "tartarus")


def test_resolve_client_view_unknown_raises():
    with pytest.raises(ValueError, match="unknown view"):
        _resolve_client_view("tartarus", "JADE", "bogus_view")


def test_valid_views_coverage():
    assert "frontal" in _VALID_VIEWS
    assert "three_quarter" in _VALID_VIEWS
    assert "profile" in _VALID_VIEWS
    assert "hero" in _VALID_VIEWS
