use pxeforge_core::{ClientRegistry, GateQueue, HostBindings, LogBus, Metrics, SettingsStore};
use pxeforge_iso_store::{IsoStore, NfsManager, SmbManager};
use std::sync::Arc;
use time::OffsetDateTime;

#[derive(Clone)]
pub struct AppState {
    pub iso_store: IsoStore,
    pub clients: Arc<ClientRegistry>,
    pub settings: Arc<SettingsStore>,
    pub gates: Arc<GateQueue>,
    /// Per-MAC iPXE script overrides. When a client matching one of
    /// these MACs requests `/boot.ipxe`, we chain straight to the
    /// configured target instead of rendering the menu.
    pub hosts: HostBindings,
    /// Lock-free metrics counters surfaced at `/metrics` in Prometheus
    /// text format. Cheap to clone (handles to atomics).
    pub metrics: Metrics,
    /// Optional SMB manager. Present when the binary was given a writable
    /// `smb_dir` at startup; `None` in pure-Linux-only deployments where
    /// Windows support is not wired in. Settings toggle drives start/stop.
    pub smb: Option<Arc<SmbManager>>,
    /// NFS share manager. Always present (mounting is opt-in by the
    /// operator from the Storage tab); `add()` requires `mount.nfs` to be
    /// available in the runtime image. Surfaces errors per-mount rather
    /// than failing the global state.
    pub nfs: NfsManager,
    /// Live log bus consumed by the Terminal tab via SSE. Operator-issued
    /// terminal commands also push synthetic lines onto it so the tail
    /// shows them inline.
    pub log_bus: Arc<LogBus>,
    /// Wall-clock instant the server bound — used for the uptime chip.
    pub started_at: OffsetDateTime,
    /// Base URL advertised to PXE clients (e.g. `http://10.0.0.5`). Used when
    /// rendering iPXE scripts so every URL resolves offline.
    pub public_base_url: String,
    /// Name of the network interface auto-detected at startup (e.g.
    /// `enp1s0`). Surfaced read-only on the Network tab. Empty if the
    /// interface couldn't be identified.
    pub nic_name: String,
    /// Subnet mask of the public interface in dotted-quad form.
    pub subnet_mask: String,
    /// Default gateway IPv4 address.
    pub gateway: String,
}
