"""Unit tests for the sRGB colour-mix helper (Qt-free)."""

from __future__ import annotations

import pytest

from mgf.brand_qt._mix import BLACK, WHITE, mix


def test_mix_endpoints_are_identity() -> None:
    assert mix("#2bb7a3", 100, BLACK) == "#2bb7a3"
    assert mix("#2bb7a3", 0, WHITE) == "#ffffff"


def test_mix_matches_upstream_color_mix_examples() -> None:
    # Expected values from 03-target-design.md §4 (±1/channel tolerance
    # is documented there; this implementation lands on these exactly).
    assert mix("#2bb7a3", 64, BLACK) == "#1c7568"  # light link (darkened teal)
    assert mix("#2bb7a3", 85, WHITE) == "#4bc2b1"  # dark link (lightened teal)
    assert mix("#5b6678", 55, WHITE) == "#a5abb5"  # dark text-secondary
    assert mix("#5b6678", 35, WHITE) == "#c6c9d0"  # dark border-strong
    assert mix("#e5484d", 16, WHITE) == "#fbe2e3"  # light error tint


def test_mix_is_lowercase_hex() -> None:
    out = mix("#E5484D", 50, "#FFFFFF")
    assert out == out.lower()
    assert len(out) == 7 and out.startswith("#")


@pytest.mark.parametrize("bad", ["", "e5484d", "#e548", "#e5484g4", "#e5484de5", "red"])
def test_mix_rejects_malformed_colours(bad: str) -> None:
    with pytest.raises(ValueError, match="hex colour"):
        mix(bad, 50, "#ffffff")
    with pytest.raises(ValueError, match="hex colour"):
        mix("#ffffff", 50, bad)


@pytest.mark.parametrize("pct", [-1, 101])
def test_mix_rejects_out_of_range_pct(pct: int) -> None:
    with pytest.raises(ValueError, match="pct"):
        mix("#ffffff", pct, "#000000")
