package store

import (
	"context"
	"os"
	"strings"
	"testing"
)

func TestListModelsLoadsEffectiveBillingSources(t *testing.T) {
	databaseURL := strings.TrimSpace(os.Getenv("AI_GATEWAY_TEST_DATABASE_URL"))
	if databaseURL == "" {
		t.Skip("set AI_GATEWAY_TEST_DATABASE_URL to run the platform-model billing source integration test")
	}

	ctx := context.Background()
	db, err := Connect(ctx, databaseURL)
	if err != nil {
		t.Fatalf("connect store: %v", err)
	}
	defer db.Close()

	models, err := db.ListModels(ctx)
	if err != nil {
		t.Fatalf("list models with effective billing sources: %v", err)
	}
	for _, model := range models {
		if model.BaseModelID == "" {
			continue
		}
		if model.BaseBillingConfig == nil {
			t.Fatalf("platform model %s did not load base billing config", model.ID)
		}
		return
	}
	t.Skip("database has no base-model-backed platform model")
}
