package handlers

import (
	"encoding/json"
	"os"
	"testing"

	"github.com/flatrender/render-svc/internal/aep"
)

// TestBuildFixResultRealAEP: set FR_TEST_AEP to a FIX .aep to see the scenes the
// binary parser scaffolds (no AE). Skipped in normal runs.
func TestBuildFixResultRealAEP(t *testing.T) {
	path := os.Getenv("FR_TEST_AEP")
	if path == "" {
		t.Skip("set FR_TEST_AEP")
	}
	data, err := os.ReadFile(path)
	if err != nil {
		t.Fatal(err)
	}
	names, err := aep.ParseNames(data)
	if err != nil {
		t.Fatal(err)
	}
	res := buildFixResult(names)
	b, _ := json.MarshalIndent(res, "", "  ")
	t.Logf("FIX scan result:\n%s", string(b))
	if len(res.Scenes) == 0 {
		t.Fatalf("expected at least one scene")
	}
	total := 0
	for _, s := range res.Scenes {
		total += len(s.Elements)
	}
	t.Logf("scenes=%d  total elements=%d  shared_colors=%d", len(res.Scenes), total, len(res.SharedColors))
}
