package runner

import (
	"testing"

	"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
)

func TestReplacePortraitAssetPlaceholders(t *testing.T) {
	got := replacePortraitAssetPlaceholders("让 <<<portrait_asset_1>>> 和 @portrait_asset2、@人像资产3 出镜", []string{"Alice", "Bob", "Carol"})
	want := "让 Alice 和 Bob、Carol 出镜"
	if got != want {
		t.Fatalf("placeholder replacement = %q, want %q", got, want)
	}
}

func TestPortraitAssetContentUsesAssetURI(t *testing.T) {
	item := portraitAssetContent("video", "asset://volces-video-1")
	video, _ := item["video_url"].(map[string]any)
	if item["type"] != "video_url" || item["role"] != "reference_video" || video["url"] != "asset://volces-video-1" {
		t.Fatalf("unexpected portrait asset content: %+v", item)
	}
}

func TestPortraitAssetSettingsRequireConfiguredVolcesAssetGroup(t *testing.T) {
	settings, ok := portraitAssetSettings(store.PortraitAssetPlatform{Config: map[string]any{
		"seedancePrivateAsset": map[string]any{
			"enabled": true, "accessKey": "ak", "secretKey": "sk", "projectName": "project", "assetGroupId": "group",
		},
	}})
	if !ok || settings.ProjectName != "project" || settings.AssetGroupID != "group" || settings.Credentials.AccessKey != "ak" {
		t.Fatalf("unexpected configured portrait asset settings: %+v ok=%v", settings, ok)
	}
	if _, ok := portraitAssetSettings(store.PortraitAssetPlatform{Config: map[string]any{"seedancePrivateAsset": map[string]any{"enabled": true, "accessKey": "ak"}}}); ok {
		t.Fatal("incomplete platform config must not enable portrait assets")
	}
}

func TestPortraitAssetHasPublicURL(t *testing.T) {
	for _, value := range []string{"https://assets.example.com/portrait.png", "http://assets.example.com/portrait.mp4"} {
		if !portraitAssetHasPublicURL(value) {
			t.Fatalf("expected public URL: %q", value)
		}
	}
	for _, value := range []string{"/uploads/portrait.png", "file:///tmp/portrait.png", "asset://portrait-id"} {
		if portraitAssetHasPublicURL(value) {
			t.Fatalf("expected non-public URL: %q", value)
		}
	}
}
