package guestnet

import (
	"context"
	"time"

	"gitea.dooplex.hu/admin/felhom-agent/internal/hub"
)

// GuestNetStatus implements hub.GuestNetReporter: the heartbeat stanza built from the last sweep.
// Pure read of already-collected state — it never probes, so a hub report can never trigger a pct
// exec storm.
//
// It returns a stanza even when no guest has been probed yet (empty guests + a checked_at), because
// "the watchdog is running and has nothing to say" must be distinguishable on the hub from "the
// watchdog is not wired", which is the shape the v0.91.0 inert seam hid behind.
func (w *Watchdog) GuestNetStatus(context.Context) *hub.GuestNetStatus {
	snap := w.Snapshot()
	out := &hub.GuestNetStatus{CheckedAt: w.now().UTC().Format(time.RFC3339)}
	for _, g := range snap {
		out.Guests = append(out.Guests, hub.GuestNetGuest{
			VMID:          g.VMID,
			State:         g.State,
			Mode:          g.Mode,
			IP:            g.IP,
			HasRoute:      g.HasRoute,
			DHClientAlive: g.DHClientAlive,
			CheckedAt:     g.CheckedAt,
			Healed:        g.Healed,
			HealSucceeded: g.HealSucceeded,
			LastHealAt:    g.LastHealAt,
			HealsLastHour: g.HealsLastHour,
			Damped:        g.Damped,
			Message:       g.Message,
		})
	}
	return out
}
