package client

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

func TestListenPortsReportJSON(t *testing.T) {
	if got := (*ListenPortsReport)(nil).JSON(); got != `{"ports":[],"count":0}` {
		t.Fatalf("nil report: %q", got)
	}
	r := &ListenPortsReport{
		Ports: []ListenPort{{Port: 22, Addr: "0.0.0.0", Proto: "tcp", Process: "sshd", PID: 99}},
	}
	got := r.JSON()
	if !strings.Contains(got, `"count":1`) || !strings.Contains(got, `"port":22`) {
		t.Fatalf("unexpected json: %s", got)
	}
	var decoded ListenPortsReport
	if err := json.Unmarshal([]byte(got), &decoded); err != nil {
		t.Fatal(err)
	}
	if decoded.Count != 1 || len(decoded.Ports) != 1 {
		t.Fatalf("decoded: %+v", decoded)
	}
}

func TestPatchStatusReportJSON(t *testing.T) {
	pending := 3
	days := 14
	reboot := true
	patch := "2026-01-01"
	r := &PatchStatusReport{
		PendingUpdates: &pending,
		LastPatchDays:  &days,
		LastPatch:      &patch,
		RebootPending:  &reboot,
	}
	got := r.JSON()
	if !strings.Contains(got, `"pending_updates":3`) {
		t.Fatalf("unexpected: %s", got)
	}
}
