"""Step definitions for TDD issue #10471: FallbackSelector per-plan budget enforcement."""

from __future__ import annotations

from behave import given, when  # type: ignore[import-untyped]
from behave.runner import Context  # type: ignore[import-untyped]


@given("I create a CostMetadata with total cost {cost:f}")
def step_create_cost_metadata_with_total_cost(context: Context, cost: float) -> None:
    from cleveragents.domain.models.core.cost_metadata import CostMetadata

    meta = CostMetadata()
    if cost > 0:
        meta.record_usage(
            input_tokens=1000,
            output_tokens=500,
            cost=cost,
            provider="openai",
        )
    context.fallback_cost_metadata = meta


@when("I create a FallbackSelector with cost tracker and cost metadata")
def step_create_fallback_with_tracker_and_metadata(context: Context) -> None:
    from cleveragents.providers.fallback_selector import FallbackSelector

    tracker = getattr(context, "fallback_cost_tracker", None) or getattr(
        context, "cost_tracker", None
    )
    context.fallback_selector = FallbackSelector(
        registry=context.fallback_registry,
        cost_tracker=tracker,
        cost_metadata=context.fallback_cost_metadata,
    )
