"""Pricing helpers for Turfslot bookings."""

from __future__ import annotations

from datetime import datetime

from .exceptions import InvalidSlotRangeError
from .models import Court, SportSlot


class SlotPriceCalculator:
    """Computes price for a validated slot."""

    def __init__(self, weekend_multiplier: float = 1.2):
        self.weekend_multiplier = weekend_multiplier

    def calculate_price(self, slot: SportSlot, court: Court) -> float:
        """Return the total price for the given slot."""
        if court.court_id != slot.court_id:
            raise InvalidSlotRangeError("slot and court mismatch.")

        if court.sport_type.upper() != slot.sport_type:
            raise InvalidSlotRangeError("slot sport and court sport mismatch.")

        if court.hourly_rate <= 0:
            raise InvalidSlotRangeError("Court hourly_rate must be positive.")

        base_price = slot.duration_hours * court.hourly_rate
        multiplier = self._determine_multiplier(slot.start_time)
        return round(base_price * multiplier, 2)

    def _determine_multiplier(self, start_time: datetime) -> float:
        return self.weekend_multiplier if start_time.weekday() >= 5 else 1.0
