package schema

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

func TestHardwareSnapshotMarshalsNewContractFields(t *testing.T) {
	week := "2024-W07"
	eventTime := "2026-03-15T14:03:11Z"
	message := "Correctable ECC error threshold exceeded"

	payload := HardwareIngestRequest{
		CollectedAt: "2026-03-15T15:00:00Z",
		Hardware: HardwareSnapshot{
			Board: HardwareBoard{SerialNumber: "SRV-001"},
			CPUs: []HardwareCPU{
				{
					HardwareComponentStatus: HardwareComponentStatus{
						ManufacturedYearWeek: &week,
					},
				},
			},
			EventLogs: []HardwareEventLog{
				{
					Source:    "bmc",
					EventTime: &eventTime,
					Message:   message,
				},
			},
		},
	}

	data, err := json.Marshal(payload)
	if err != nil {
		t.Fatalf("marshal: %v", err)
	}
	text := string(data)
	if !strings.Contains(text, `"manufactured_year_week":"2024-W07"`) {
		t.Fatalf("missing manufactured_year_week: %s", text)
	}
	if !strings.Contains(text, `"event_logs":[{"source":"bmc","event_time":"2026-03-15T14:03:11Z","message":"Correctable ECC error threshold exceeded"}]`) {
		t.Fatalf("missing event_logs payload: %s", text)
	}
}
