use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct UsageReport {
pub api_key_name: String,
pub since: DateTime<Utc>,
pub until: DateTime<Utc>,
pub sessions: SessionCounts,
pub compute: ComputeTotals,
}
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub struct SessionCounts {
pub started: u64,
pub completed: u64,
pub failed: u64,
}
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub struct ComputeTotals {
pub executed_slot_count: u64,
pub session_duration_ms: u64,
}
impl SessionCounts {
pub fn saturating_add(self, other: Self) -> Self {
Self {
started: self.started.saturating_add(other.started),
completed: self.completed.saturating_add(other.completed),
failed: self.failed.saturating_add(other.failed),
}
}
}
impl ComputeTotals {
pub fn saturating_add(self, other: Self) -> Self {
Self {
executed_slot_count: self
.executed_slot_count
.saturating_add(other.executed_slot_count),
session_duration_ms: self
.session_duration_ms
.saturating_add(other.session_duration_ms),
}
}
}