package llm

import (
	"testing"

	"github.com/sundynix/sundynix-shared/contract"
)

// Pool.ModelHealth 应把主备链各模型的名字/角色与其熔断态正确配对上报。
func TestPool_ModelHealth(t *testing.T) {
	p := NewPool()

	// 主 + 1 备 → failover 链，两模型都在线(closed)。
	p.SetConfig(&contract.ModelConfig{
		Provider: "openai-compatible", BaseURL: "http://primary", APIKey: "k", Model: "primary-m",
		Fallbacks: []contract.ModelConfig{
			{Provider: "openai-compatible", BaseURL: "http://backup", APIKey: "k", Model: "backup-m"},
		},
	})
	h := p.ModelHealth()
	if len(h) != 2 {
		t.Fatalf("主+备应 2 条, got %d: %+v", len(h), h)
	}
	if h[0].Role != "primary" || h[0].Model != "primary-m" || h[0].State != "closed" {
		t.Errorf("主模型态错: %+v", h[0])
	}
	if h[1].Role != "fallback" || h[1].Model != "backup-m" || h[1].State != "closed" {
		t.Errorf("备模型态错: %+v", h[1])
	}

	// 单模型 → 无 failover 链，state=single。
	p.SetConfig(&contract.ModelConfig{
		Provider: "openai-compatible", BaseURL: "http://only", APIKey: "k", Model: "only-m",
	})
	h = p.ModelHealth()
	if len(h) != 1 || h[0].State != "single" || h[0].Role != "primary" {
		t.Fatalf("单模型应 1 条 single/primary, got %+v", h)
	}

	// 未配置 → 空。
	p.SetConfig(nil)
	if h := p.ModelHealth(); len(h) != 0 {
		t.Fatalf("未配置应空, got %+v", h)
	}
}
