package nsc

import "testing"

func TestInstanceStoppedRequiresObservedTerminalState(t *testing.T) {
	t.Parallel()

	cases := []struct {
		name   string
		output string
		want   bool
	}{
		{name: "empty output", output: "", want: false},
		{name: "empty response", output: "[]", want: false},
		{name: "no resources yet", output: `[{"per_resource":{}}]`, want: false},
		{name: "resource without containers", output: `[{"per_resource":{"runner":{}}}]`, want: false},
		{name: "running container", output: `[{"per_resource":{"runner":{"container":[{"status":"running"}]}}}]`, want: false},
		{name: "stopped container", output: `[{"per_resource":{"runner":{"container":[{"status":"stopped"}]}}}]`, want: true},
		{name: "terminated container", output: `[{"per_resource":{"runner":{"container":[{"status":"running","terminated_at":"2026-06-07T15:00:00Z"}]}}}]`, want: true},
		{name: "tombstone", output: `[{"per_resource":{"runner":{"tombstone":"destroyed"}}}]`, want: true},
	}

	for _, tc := range cases {
		tc := tc
		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()
			got := instanceStopped(tc.output)
			if got != tc.want {
				t.Fatalf("instanceStopped(%s) = %v, want %v", tc.output, got, tc.want)
			}
		})
	}
}
