package itemregistry

import (
	"encoding/json"
	"strings"
	"testing"
)

func TestItemResponseSchemaIsPrivateAndStructural(t *testing.T) {
	schema, err := loadResponseSchema()
	if err != nil {
		t.Fatalf("loadResponseSchema() error = %v", err)
	}
	if schema.Key != ResponseSchemaKey || schema.ID != ResponseSchemaID || schema.Name != ResponseSchemaName || schema.Version != SchemaVersion || !strings.HasPrefix(schema.SHA256, "sha256:") || !json.Valid(schema.JSONSchema) {
		t.Fatalf("schema = %#v, want item response schema", schema)
	}
	var document map[string]any
	if err := json.Unmarshal(schema.JSONSchema, &document); err != nil {
		t.Fatal(err)
	}
	encoded, err := json.Marshal(document)
	if err != nil || strings.Contains(string(encoded), `"id"`) || !strings.Contains(string(encoded), `"additionalProperties":false`) {
		t.Fatalf("schema = %s, want strict private response without durable ID", encoded)
	}
}
