"""
Pricing service for Aimantis dashboard.

Calculates average nightly rates (ADR) for:
- Today
- Next 7 days
- Next 30 days

Uses centralized dashboard_metrics_service for proper PMS stay-night
expansion logic consistent with ISTAT and city tax calculations.

All monetary calculations use Decimal to avoid floating-point issues.
"""

from datetime import date
from typing import Dict, Optional

from dashboard.services.dashboard_metrics_service import calculate_all_adr_metrics
from dashboard.services.utils import get_today


class PricingService:
    """
    Service for calculating average nightly rates (ADR).
    
    Delegates to centralized dashboard_metrics_service which implements
    proper PMS stay-night expansion logic:
    - check_in_date is INCLUDED
    - check_out_date is EXCLUDED
    - Revenue allocated per night: total_price / length_of_stay
    - Only checked-in bookings for today
    - All bookings (checked-in + future) for 7/30-day windows
    
    All monetary calculations use Decimal to avoid
    floating-point precision issues.
    """
    
    def __init__(self, structure_id: Optional[int] = None):
        """
        Initialize the pricing service.
        
        Args:
            structure_id: Optional structure ID for multi-tenant filtering
        """
        self.structure_id = structure_id
        self.today = get_today()
    
    def get_average_rates(self) -> Dict[str, float]:
        """
        Get all average rate metrics in a single optimized call.
        
        Uses centralized ADR calculation with proper PMS logic.
        
        Returns:
            Dict with average rates for different time windows:
            - today: ADR for today (checked-in bookings only)
            - next_7_days: ADR for next 7 days (all bookings)
            - next_30_days: ADR for next 30 days (all bookings)
        """
        return calculate_all_adr_metrics(
            structure_id=self.structure_id,
            today=self.today,
        )
