package oci

import (
	"testing"

	"github.com/oracle/oci-go-sdk/v65/generativeaiinference"
)

// TestSdkUsageCachedTokens 断言 embed 用量映射:缓存命中挂 details,仅命中 >0 时出现。
func TestSdkUsageCachedTokens(t *testing.T) {
	p, c, tot, cached := 10, 5, 15, 8
	u := sdkUsageToIR(&generativeaiinference.Usage{PromptTokens: &p, CompletionTokens: &c, TotalTokens: &tot,
		PromptTokensDetails: &generativeaiinference.PromptTokensDetails{CachedTokens: &cached}})
	if u.PromptTokens != 10 || u.CompletionTokens != 5 || u.TotalTokens != 15 {
		t.Fatalf("usage 映射错误: %+v", u)
	}
	if u.PromptTokensDetails == nil || u.PromptTokensDetails.CachedTokens != 8 {
		t.Fatalf("cachedTokens 未映射: %+v", u.PromptTokensDetails)
	}
	zero := 0
	if got := sdkUsageToIR(&generativeaiinference.Usage{PromptTokens: &p, PromptTokensDetails: &generativeaiinference.PromptTokensDetails{CachedTokens: &zero}}); got.PromptTokensDetails != nil {
		t.Fatalf("零命中不应带 details: %+v", got.PromptTokensDetails)
	}
	if sdkUsageToIR(nil) != nil {
		t.Fatal("nil usage 应返回 nil")
	}
}
