use chrono::serde::ts_nanoseconds;
use chrono::{DateTime, Utc};
use derive_more::{Display, From};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Telemetry {
    #[serde(with = "ts_nanoseconds")]
    pub timestamp: DateTime<Utc>,
    pub message: TelemetryMessage,
}

#[derive(Copy, Clone, Debug, Display, Serialize, Deserialize)]
pub enum SwitchBank {
    A,
    B,
}

#[derive(Clone, Debug, Serialize, Deserialize, From)]
pub enum TelemetryMessage {
    SwitchState {
        bank: SwitchBank,
        switches: [bool; 16],
    },
    CommsState(CommsState),
}

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct CommsState {
    pub tx_packets: u32,
    pub rx_packets: u32,
    pub tx_bytes: u32,
    pub rx_bytes: u32,
    pub tx_errors: u32,
    pub rx_errors: u32,
}
