from __future__ import annotations

import pytest

from services.currency import CurrencyValidationError, normalise_currency, require_currency


@pytest.mark.parametrize(
    "raw,expected",
    [
        ("usd", "USD"),
        (" Eur ", "EUR"),
        ("JPY", "JPY"),
        (None, None),
    ],
)
def test_normalise_currency_valid_inputs(raw: str | None, expected: str | None) -> None:
    assert normalise_currency(raw) == expected


@pytest.mark.parametrize("raw", ["usd1", "us", "", "12", "X Y Z"])
def test_normalise_currency_invalid_inputs(raw: str) -> None:
    with pytest.raises(CurrencyValidationError):
        normalise_currency(raw)


def test_require_currency_with_value() -> None:
    assert require_currency("gbp", default="usd") == "GBP"


def test_require_currency_with_default() -> None:
    assert require_currency(None, default="cad") == "CAD"


def test_require_currency_missing_default() -> None:
    with pytest.raises(CurrencyValidationError):
        require_currency(None)


def test_require_currency_invalid_default() -> None:
    with pytest.raises(CurrencyValidationError):
        require_currency(None, default="invalid")
