use crate::error::AybError;
use crate::{from_str, try_from_i16};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::collections::HashMap;
use std::str::FromStr;
#[derive(Serialize_repr, Deserialize_repr, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(i16)]
pub enum SnapshotType {
Automatic = 0,
Manual = 1,
}
from_str!(SnapshotType, {
"automatic" => SnapshotType::Automatic,
"manual" => SnapshotType::Manual
});
try_from_i16!(SnapshotType, {
0 => SnapshotType::Automatic,
1 => SnapshotType::Manual
});
impl SnapshotType {
#[allow(clippy::wrong_self_convention)]
pub fn to_str(&self) -> &str {
match self {
SnapshotType::Automatic => "automatic",
SnapshotType::Manual => "manual",
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Snapshot {
pub snapshot_id: String,
pub snapshot_type: i16,
}
impl Snapshot {
pub fn to_header_map(&self) -> Result<HashMap<String, String>, AybError> {
let mut headers = HashMap::new();
headers.insert(
"snapshot_type".to_string(),
SnapshotType::try_from(self.snapshot_type)?
.to_str()
.to_string(),
);
Ok(headers)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ListSnapshotResult {
pub last_modified_at: DateTime<Utc>,
pub snapshot_id: String,
}