"""Scenario evaluation services including pricing integration."""

from __future__ import annotations

from dataclasses import dataclass
from typing import Iterable

from models.scenario import Scenario
from services.pricing import (
    PricingInput,
    PricingMetadata,
    PricingResult,
    calculate_pricing,
)


@dataclass(slots=True)
class ScenarioPricingConfig:
    """Configuration for pricing evaluation within a scenario."""

    metadata: PricingMetadata | None = None


@dataclass(slots=True)
class ScenarioPricingSnapshot:
    """Captured pricing results for a scenario."""

    scenario_id: int
    results: list[PricingResult]


class ScenarioPricingEvaluator:
    """Evaluate scenario profitability inputs using pricing services."""

    def __init__(self, config: ScenarioPricingConfig | None = None) -> None:
        self._config = config or ScenarioPricingConfig()

    def evaluate(
        self,
        scenario: Scenario,
        *,
        inputs: Iterable[PricingInput],
        metadata_override: PricingMetadata | None = None,
    ) -> ScenarioPricingSnapshot:
        metadata = metadata_override or self._config.metadata
        results: list[PricingResult] = []
        for pricing_input in inputs:
            result = calculate_pricing(
                pricing_input,
                metadata=metadata,
                currency=scenario.currency,
            )
            results.append(result)
        return ScenarioPricingSnapshot(scenario_id=scenario.id, results=results)
