package billing_test

import (
	"testing"

	"github.com/stretchr/testify/assert"

	"github.com/veylant/ia-gateway/internal/billing"
)

func TestBilling_OpenAI_GPT4o_ExactMatch(t *testing.T) {
	cost := billing.CostUSD("openai", "gpt-4o", 1000)
	assert.InDelta(t, 0.005, cost, 1e-9)
}

func TestBilling_OpenAI_GPT4oMini(t *testing.T) {
	cost := billing.CostUSD("openai", "gpt-4o-mini", 1000)
	assert.InDelta(t, 0.00015, cost, 1e-9)
}

func TestBilling_OpenAI_GPT4o_PrefixVersioned(t *testing.T) {
	// "gpt-4o-2024-08-06" should match prefix "openai/gpt-4o"
	cost := billing.CostUSD("openai", "gpt-4o-2024-08-06", 1000)
	assert.InDelta(t, 0.005, cost, 1e-9)
}

func TestBilling_Anthropic_Sonnet(t *testing.T) {
	cost := billing.CostUSD("anthropic", "claude-3-5-sonnet", 2000)
	assert.InDelta(t, 0.006, cost, 1e-9)
}

func TestBilling_Ollama_ZeroCost(t *testing.T) {
	cost := billing.CostUSD("ollama", "llama3.1", 10000)
	assert.Equal(t, 0.0, cost)
}

func TestBilling_Unknown_ZeroCost(t *testing.T) {
	cost := billing.CostUSD("unknown", "mystery-model", 5000)
	assert.Equal(t, 0.0, cost)
}

func TestBilling_ZeroTokens(t *testing.T) {
	cost := billing.CostUSD("openai", "gpt-4o", 0)
	assert.Equal(t, 0.0, cost)
}

func TestBilling_NegativeTokens(t *testing.T) {
	cost := billing.CostUSD("openai", "gpt-4o", -100)
	assert.Equal(t, 0.0, cost)
}
