"""REC-216: model_profiles.get_cost fails loud on an absent cost.

A profile with neither cost_per_image nor cost_per_second previously returned a
silent 0.0 (spend undercount). Now it raises CostMissingError; an explicit
cost_*: 0.0 (legitimate billing-zero) is still returned; telemetry callers can
opt into the old behavior with allow_missing=True.
"""

import pytest

from recoil.core import model_profiles as mp
from recoil.core.exceptions import CostMissingError


def test_real_cost_preserved():
    # models with a top-level cost are unaffected
    assert mp.get_cost("gemini-3-pro-image-preview") == 0.134
    assert mp.get_cost("seeddance-2.0") == 0.3034


def test_raises_on_absent_cost():
    # eleven_multilingual_v2 has no per-image/second cost (priced per char)
    with pytest.raises(CostMissingError):
        mp.get_cost("eleven_multilingual_v2")


def test_allow_missing_returns_zero():
    assert mp.get_cost("eleven_multilingual_v2", allow_missing=True) == 0.0


def test_explicit_zero_is_preserved_not_raised(monkeypatch):
    # an explicit billing-zero is a present key → returned, never raised
    monkeypatch.setattr(mp, "get_profile", lambda mid: {"cost_per_image": 0.0})
    assert mp.get_cost("explicit-free-model") == 0.0
