package packs

import (
	"strings"
	"testing"
)

func TestPlatformUXPayloadStrictDecodeConsumesSnakeCase(t *testing.T) {
	themes := parseThemes()
	if len(themes) == 0 {
		t.Fatal("parseThemes returned no themes")
	}
	if themes[0].Name != "Default" || !themes[0].IsActive {
		t.Fatalf("Default theme decoded incorrectly: %#v", themes[0])
	}
	if themes[0].LogoURL == nil || *themes[0].LogoURL != "/logo.png" {
		t.Fatalf("Default theme logo_url decoded incorrectly: %#v", themes[0].LogoURL)
	}

	components := parseUIComponents()
	var found bool
	for _, component := range components {
		if component.Name == "LayoutEditor" {
			found = true
			if !component.IsEmbeddable {
				t.Fatalf("LayoutEditor is_embeddable decoded as false")
			}
		}
	}
	if !found {
		t.Fatal("LayoutEditor component not found")
	}
}

func TestPlatformUXPayloadStrictDecodeRequiresThemeIsActive(t *testing.T) {
	_, err := parseThemeSeeds([]byte(`{"themes":[{"name":"Default","colors":{},"density":"comfortable","logo_url":"/logo.png"}]}`))
	if err == nil || !strings.Contains(err.Error(), "missing required is_active") {
		t.Fatalf("parseThemeSeeds error = %v, want missing is_active", err)
	}
}

func TestPlatformUXPayloadStrictDecodeRequiresThemeLogoURL(t *testing.T) {
	_, err := parseThemeSeeds([]byte(`{"themes":[{"name":"Default","is_active":true,"colors":{},"density":"comfortable"}]}`))
	if err == nil || !strings.Contains(err.Error(), "missing required logo_url") {
		t.Fatalf("parseThemeSeeds error = %v, want missing logo_url", err)
	}
}

func TestPlatformUXPayloadStrictDecodeRequiresUIIsEmbeddable(t *testing.T) {
	_, err := parseUIComponentSeeds([]byte(`{"components":[{"name":"LayoutEditor","type":"widget","description":"Layout Editor Component"}]}`))
	if err == nil || !strings.Contains(err.Error(), "missing required is_embeddable") {
		t.Fatalf("parseUIComponentSeeds error = %v, want missing is_embeddable", err)
	}
}
