Skip to main content

AirLibrary/CLI/
ResponseTypes.rs

1#![allow(unused_variables, dead_code, unused_imports)]
2
3//! Response DTO structs returned by daemon IPC calls and serialised to
4//! stdout by `OutputFormatter`. Keeping these separate from the parser and
5//! handler code makes the wire contract easy to review and unit-test.
6
7use std::collections::HashMap;
8
9use chrono::{DateTime, Utc};
10use serde::{Deserialize, Serialize};
11
12/// Overall daemon + services status.
13#[derive(Debug, Serialize, Deserialize)]
14pub struct StatusResponse {
15	pub daemon_running:bool,
16	pub uptime_secs:u64,
17	pub version:String,
18	pub services:HashMap<String, ServiceStatus>,
19	pub timestamp:String,
20}
21
22/// Per-service status inside a `StatusResponse`.
23#[derive(Debug, Serialize, Deserialize)]
24pub struct ServiceStatus {
25	pub name:String,
26	pub running:bool,
27	pub health:ServiceHealth,
28	pub uptime_secs:u64,
29	pub error:Option<String>,
30}
31
32/// Coarse service health classification.
33#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
34#[serde(rename_all = "UPPERCASE")]
35pub enum ServiceHealth {
36	Healthy,
37	Degraded,
38	Unhealthy,
39	Unknown,
40}
41
42/// Aggregated performance metrics snapshot.
43#[derive(Debug, Serialize, Deserialize)]
44pub struct MetricsResponse {
45	pub timestamp:String,
46	pub memory_used_mb:f64,
47	pub memory_available_mb:f64,
48	pub cpu_usage_percent:f64,
49	pub disk_used_mb:u64,
50	pub disk_available_mb:u64,
51	pub active_connections:u32,
52	pub processed_requests:u64,
53	pub failed_requests:u64,
54	pub service_metrics:HashMap<String, ServiceMetrics>,
55}
56
57/// Per-service request latency counters.
58#[derive(Debug, Serialize, Deserialize)]
59pub struct ServiceMetrics {
60	pub name:String,
61	pub requests_total:u64,
62	pub requests_success:u64,
63	pub requests_failed:u64,
64	pub average_latency_ms:f64,
65	pub p99_latency_ms:f64,
66}
67
68/// Result of a health-check sweep across all services.
69#[derive(Debug, Serialize, Deserialize)]
70pub struct HealthCheckResponse {
71	pub overall_healthy:bool,
72	pub overall_health_percentage:f64,
73	pub services:HashMap<String, ServiceHealthDetail>,
74	pub timestamp:String,
75}
76
77/// Fine-grained health detail for one service.
78#[derive(Debug, Serialize, Deserialize)]
79pub struct ServiceHealthDetail {
80	pub name:String,
81	pub healthy:bool,
82	pub response_time_ms:u64,
83	pub last_check:String,
84	pub details:String,
85}
86
87/// Configuration key/value read result.
88#[derive(Debug, Serialize, Deserialize)]
89pub struct ConfigResponse {
90	pub key:Option<String>,
91	pub value:serde_json::Value,
92	pub path:String,
93	pub modified:String,
94}
95
96/// Single structured log line.
97#[derive(Debug, Serialize, Deserialize)]
98pub struct LogEntry {
99	pub timestamp:DateTime<Utc>,
100	pub level:String,
101	pub service:Option<String>,
102	pub message:String,
103	pub context:Option<serde_json::Value>,
104}
105
106/// Active IPC connection metadata.
107#[derive(Debug, Serialize, Deserialize)]
108pub struct ConnectionInfo {
109	pub id:String,
110	pub remote_address:String,
111	pub connected_at:DateTime<Utc>,
112	pub service:Option<String>,
113	pub active:bool,
114}
115
116/// Full daemon state snapshot (debug dump).
117#[derive(Debug, Serialize, Deserialize)]
118pub struct DaemonState {
119	pub timestamp:DateTime<Utc>,
120	pub version:String,
121	pub uptime_secs:u64,
122	pub services:HashMap<String, serde_json::Value>,
123	pub connections:Vec<ConnectionInfo>,
124	pub plugin_state:serde_json::Value,
125}