use crate::method::HttpMethod;
pub const EMERGENCY_STOP_PATH: &str = "/emergency-stop";
pub const EMERGENCY_RESUME_PATH: &str = "/emergency-resume";
pub const EMERGENCY_STATUS_PATH: &str = "/emergency-status";
pub const EVALUATE_PLAN_PATH: &str = "/evaluate-plan";
pub const APPROVALS_PENDING_PATH: &str = "/approvals/pending";
pub const APPROVALS_GET_PATH: &str = "/approvals/{id}";
pub const APPROVALS_RESPOND_PATH: &str = "/approvals/{id}/respond";
pub const APPROVALS_BATCH_RESPOND_PATH: &str = "/approvals/batch/respond";
#[must_use]
pub const fn approval_route_registrations() -> [EmergencyRouteRegistration; 4] {
[
EmergencyRouteRegistration {
method: HttpMethod::Get,
path: APPROVALS_PENDING_PATH,
name: "approvals_pending",
},
EmergencyRouteRegistration {
method: HttpMethod::Get,
path: APPROVALS_GET_PATH,
name: "approvals_get",
},
EmergencyRouteRegistration {
method: HttpMethod::Post,
path: APPROVALS_RESPOND_PATH,
name: "approvals_respond",
},
EmergencyRouteRegistration {
method: HttpMethod::Post,
path: APPROVALS_BATCH_RESPOND_PATH,
name: "approvals_batch_respond",
},
]
}
pub const EMERGENCY_ADMIN_TOKEN_HEADER: &str = "X-Admin-Token";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EmergencyRouteRegistration {
pub method: HttpMethod,
pub path: &'static str,
pub name: &'static str,
}
#[must_use]
pub const fn emergency_route_registrations() -> [EmergencyRouteRegistration; 3] {
[
EmergencyRouteRegistration {
method: HttpMethod::Post,
path: EMERGENCY_STOP_PATH,
name: "emergency_stop",
},
EmergencyRouteRegistration {
method: HttpMethod::Post,
path: EMERGENCY_RESUME_PATH,
name: "emergency_resume",
},
EmergencyRouteRegistration {
method: HttpMethod::Get,
path: EMERGENCY_STATUS_PATH,
name: "emergency_status",
},
]
}
pub const COMPLIANCE_SCORE_PATH: &str = "/compliance/score";
pub const REGULATORY_RECEIPTS_PATH: &str = "/regulatory/receipts";
pub const REGULATORY_TOKEN_HEADER: &str = "X-Regulatory-Token";
#[must_use]
pub const fn regulatory_route_registrations() -> [EmergencyRouteRegistration; 2] {
[
EmergencyRouteRegistration {
method: HttpMethod::Post,
path: COMPLIANCE_SCORE_PATH,
name: "compliance_score",
},
EmergencyRouteRegistration {
method: HttpMethod::Get,
path: REGULATORY_RECEIPTS_PATH,
name: "regulatory_receipts",
},
]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn emergency_route_constants_match_spec() {
assert_eq!(EMERGENCY_STOP_PATH, "/emergency-stop");
assert_eq!(EMERGENCY_RESUME_PATH, "/emergency-resume");
assert_eq!(EMERGENCY_STATUS_PATH, "/emergency-status");
assert_eq!(EMERGENCY_ADMIN_TOKEN_HEADER, "X-Admin-Token");
}
#[test]
fn regulatory_route_constants_match_spec() {
assert_eq!(COMPLIANCE_SCORE_PATH, "/compliance/score");
assert_eq!(REGULATORY_RECEIPTS_PATH, "/regulatory/receipts");
assert_eq!(REGULATORY_TOKEN_HEADER, "X-Regulatory-Token");
let registrations = regulatory_route_registrations();
assert_eq!(registrations.len(), 2);
let names: Vec<&str> = registrations.iter().map(|r| r.name).collect();
assert!(names.contains(&"compliance_score"));
assert!(names.contains(&"regulatory_receipts"));
}
#[test]
fn registrations_cover_all_three_endpoints() {
let registrations = emergency_route_registrations();
assert_eq!(registrations.len(), 3);
let names: Vec<&str> = registrations.iter().map(|r| r.name).collect();
assert!(names.contains(&"emergency_stop"));
assert!(names.contains(&"emergency_resume"));
assert!(names.contains(&"emergency_status"));
let stop = registrations.iter().find(|r| r.name == "emergency_stop");
assert!(
matches!(stop, Some(r) if matches!(r.method, HttpMethod::Post)),
"stop registration must exist and use POST"
);
let status = registrations.iter().find(|r| r.name == "emergency_status");
assert!(
matches!(status, Some(r) if matches!(r.method, HttpMethod::Get)),
"status registration must exist and use GET"
);
}
}