package edgevalidate

import (
	"strings"
	"testing"

	"iop/packages/go/config"
)

func TestValidateEdgeConfigRequiresProviderAdapter(t *testing.T) {
	err := ValidateEdgeConfig(&config.EdgeConfig{Nodes: []config.NodeDefinition{{Alias: "node", Token: "token"}}})
	if err == nil || !strings.Contains(err.Error(), "at least one adapter") {
		t.Fatalf("error = %v", err)
	}
}

func TestValidateEdgeConfigAcceptsOllamaProvider(t *testing.T) {
	err := ValidateEdgeConfig(&config.EdgeConfig{Nodes: []config.NodeDefinition{{
		Alias: "node", Token: "token", Providers: []config.NodeProviderConf{{
			ID: "ollama-local", Type: "ollama", Category: config.CategoryLocalInference,
			BaseURL: "http://127.0.0.1:11434", Models: []string{"model"}, Capacity: 1,
		}},
	}}})
	if err != nil {
		t.Fatal(err)
	}
}

func TestValidateEdgeConfigRejectsUnknownProvider(t *testing.T) {
	err := ValidateEdgeConfig(&config.EdgeConfig{Nodes: []config.NodeDefinition{{
		Alias: "node", Token: "token", Providers: []config.NodeProviderConf{{
			ID: "unknown", Type: "unknown", Category: config.CategoryAPI, Models: []string{"model"}, Capacity: 1,
		}},
	}}})
	if err == nil || !strings.Contains(err.Error(), "unknown provider type") {
		t.Fatalf("error = %v", err)
	}
}
