package gateway

import (
	"encoding/json"
	"testing"

	"github.com/rose_cat707/luminary/internal/model"
)

func TestIngressModelID(t *testing.T) {
	if got := IngressModelID(model.ModelEntry{ModelID: "text-embedding-3-small", Alias: "my-embed"}); got != "my-embed" {
		t.Fatalf("got %q", got)
	}
	if got := (model.ModelEntry{ModelID: "gpt-4o"}).IngressID(); got != "gpt-4o" {
		t.Fatalf("got %q", got)
	}
}

func TestRewriteModelInBody(t *testing.T) {
	body := []byte(`{"model":"my-embed","input":"hi"}`)
	out, err := rewriteModelInBody(body, "text-embedding-3-small")
	if err != nil {
		t.Fatal(err)
	}
	var payload map[string]string
	if err := json.Unmarshal(out, &payload); err != nil {
		t.Fatal(err)
	}
	if payload["model"] != "text-embedding-3-small" {
		t.Fatalf("got %q", payload["model"])
	}
}
