"""Business rule and validator tests — Phase 7.0."""
from __future__ import annotations

import pytest

from app.validators import (
    forbid_direct_balance_mutation,
    validate_campaign_dates,
    validate_code,
    validate_non_negative_int,
)
from shared.exceptions import AppError
from datetime import date


def test_validate_code_normalizes():
    assert validate_code("gold-1") == "GOLD-1"


def test_forbid_direct_balance_mutation():
    with pytest.raises(AppError) as exc:
        forbid_direct_balance_mutation({"balance": 10})
    assert exc.value.error_code == "direct_balance_forbidden"


def test_non_negative_points():
    assert validate_non_negative_int(0, field="points_cost") == 0
    with pytest.raises(AppError):
        validate_non_negative_int(-1, field="points_cost")


def test_campaign_date_order():
    validate_campaign_dates(date(2026, 1, 1), date(2026, 2, 1))
    with pytest.raises(AppError):
        validate_campaign_dates(date(2026, 3, 1), date(2026, 1, 1))
