from datetime import datetime, timedelta, timezone

import pytest

from turfslot_utils import InvalidSlotRangeError, SlotRangeValidator


def _dt(hours: int) -> datetime:
    base = datetime(2025, 1, 10, 8, 0, tzinfo=timezone.utc)
    return base + timedelta(hours=hours)


def test_valid_slot_passes():
    validator = SlotRangeValidator()
    slot = validator.validate("Badminton", "C1", _dt(0), _dt(2))
    assert slot.duration_hours == pytest.approx(2.0)
    assert slot.sport_type == "BADMINTON"


def test_end_time_before_start_time_fails():
    validator = SlotRangeValidator()
    with pytest.raises(InvalidSlotRangeError):
        validator.validate("Tennis", "C2", _dt(2), _dt(1))


def test_duration_too_long_fails():
    validator = SlotRangeValidator(max_duration_hours=3)
    with pytest.raises(InvalidSlotRangeError):
        validator.validate("Tennis", "C2", _dt(0), _dt(4))


def test_invalid_sport_type_fails():
    validator = SlotRangeValidator()
    with pytest.raises(InvalidSlotRangeError):
        validator.validate("CRICKET", "C9", _dt(0), _dt(1))
