use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize)]
pub struct RecordInfo {
pub uuid: String,
pub title: Option<String>,
#[serde(rename = "startDatetime")]
pub start_datetime: Option<String>,
#[serde(rename = "endDatetime")]
pub end_datetime: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct MarkerInfo {
pub uuid: String,
#[serde(rename = "startDatetime")]
pub start_datetime: Option<String>,
}
#[derive(Debug, Clone, Copy)]
pub enum ExportFormat {
Csv,
Edf,
}
impl ExportFormat {
#[must_use]
pub fn as_str(&self) -> &'static str {
match self {
ExportFormat::Csv => "CSV",
ExportFormat::Edf => "EDF",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_deserialize_record_info() {
let json = r#"{
"uuid": "record-uuid-789",
"title": "Calibration Session 1",
"startDatetime": "2024-01-15T10:30:00Z"
}"#;
let record: RecordInfo = serde_json::from_str(json).unwrap();
assert_eq!(record.uuid, "record-uuid-789");
assert_eq!(record.title.as_deref(), Some("Calibration Session 1"));
assert!(record.end_datetime.is_none());
}
#[test]
fn test_deserialize_marker_info() {
let json = r#"{
"uuid": "marker-uuid-abc",
"startDatetime": "2024-01-15T10:30:05Z"
}"#;
let marker: MarkerInfo = serde_json::from_str(json).unwrap();
assert_eq!(marker.uuid, "marker-uuid-abc");
}
#[test]
fn test_export_format_strings() {
assert_eq!(ExportFormat::Csv.as_str(), "CSV");
assert_eq!(ExportFormat::Edf.as_str(), "EDF");
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateRecordRequest {
pub record_id: String,
pub title: Option<String>,
pub description: Option<String>,
pub tags: Option<Vec<String>>,
}
impl UpdateRecordRequest {
pub fn new(record_id: impl Into<String>) -> Self {
Self {
record_id: record_id.into(),
title: None,
description: None,
tags: None,
}
}
}