righvalor 0.1.0

RighValor: AI Infrastructure and Applications Framework for the Far Edge
use serde::{Deserialize, Serialize};

use crate::{service::ValorServiceId, types::ValorID};

/// Minimal capacity reported by a worker to the master
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
pub struct ValorWorkerCapacity {
    pub total_cpu: u32,
    pub total_mem_mb: u32,
    pub free_cpu: u32,
    pub free_mem_mb: u32,
    /// Average CPU usage percentage across all logical CPUs (0.0 - 100.0)
    pub cpu_usage_pct: f32,
}

/// Heartbeat payload from worker to master
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkerHeartbeat {
    pub id: ValorID,
    /// Milliseconds since UNIX epoch
    pub ts_mono_ms: u64,
    /// Monotonic sequence number per worker for ordering
    pub seq_no: u64,
}

/// Capacity snapshot payload from worker to master
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CapacitySnapshot {
    pub id: ValorID,
    /// Milliseconds since UNIX epoch
    pub ts_mono_ms: u64,
    /// Captured capacity at the time of snapshot
    pub capacity: ValorWorkerCapacity,
}

/// Services snapshot payload from worker to master
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServicesSnapshot {
    pub id: ValorID,
    /// Milliseconds since UNIX epoch
    pub ts_mono_ms: u64,
    /// Report service IDs only (lighter payload)
    pub services: Vec<ValorServiceId>,
    /// Schema version for forward compatibility
    pub version: u32,
}

/// # Valor Worker Event
///
/// Events that represent significant state changes or occurrences within
/// a Valor Worker that other actors might need to be notified about.
///
/// These events are emitted by the worker actor and can be subscribed to
/// by other components for monitoring, logging, or reactive coordination.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ValorWorkerEvent {
    /// Lightweight liveness heartbeat
    Heartbeat(WorkerHeartbeat),
    /// Services report (low frequency or on change)
    ServicesReport(ServicesSnapshot),
    /// Capacity report (periodic)
    CapacityReport(CapacitySnapshot),
}