use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Download {
#[serde(rename = "dataset_id")]
pub dataset_id: String,
#[serde(rename = "format")]
pub format: String,
#[serde(rename = "outcome")]
pub outcome: Outcome,
#[serde(rename = "sample")]
pub sample: bool,
#[serde(rename = "open")]
pub open: bool,
#[serde(rename = "bytes", deserialize_with = "Option::deserialize")]
pub bytes: Option<i64>,
#[serde(rename = "http_status", deserialize_with = "Option::deserialize")]
pub http_status: Option<i32>,
#[serde(rename = "apikey_id", deserialize_with = "Option::deserialize")]
pub apikey_id: Option<String>,
#[serde(rename = "client_ip", deserialize_with = "Option::deserialize")]
pub client_ip: Option<String>,
#[serde(rename = "user_agent", deserialize_with = "Option::deserialize")]
pub user_agent: Option<String>,
#[serde(rename = "created")]
pub created: chrono::DateTime<chrono::FixedOffset>,
}
impl Download {
pub fn new(
dataset_id: String,
format: String,
outcome: Outcome,
sample: bool,
open: bool,
bytes: Option<i64>,
http_status: Option<i32>,
apikey_id: Option<String>,
client_ip: Option<String>,
user_agent: Option<String>,
created: chrono::DateTime<chrono::FixedOffset>,
) -> Download {
Download {
dataset_id,
format,
outcome,
sample,
open,
bytes,
http_status,
apikey_id,
client_ip,
user_agent,
created,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Outcome {
#[serde(rename = "ok")]
Ok,
#[serde(rename = "unauthorized")]
Unauthorized,
#[serde(rename = "denied")]
Denied,
#[serde(rename = "expired")]
Expired,
#[serde(rename = "unknown")]
Unknown,
#[serde(rename = "unavailable")]
Unavailable,
}
impl Default for Outcome {
fn default() -> Outcome {
Self::Ok
}
}