use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize)]
pub struct Envelope<T> {
#[serde(alias = "errCode")]
pub code: Option<i64>,
#[serde(alias = "errInfo", alias = "msg", alias = "message")]
pub message: Option<String>,
pub data: Option<T>,
}
impl<T> Envelope<T> {
pub fn is_ok(&self) -> bool {
self.code.unwrap_or(0) == 0
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct MediaId(pub String);
impl std::fmt::Display for MediaId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MediaKind {
Insv360,
FlatVideo,
Photo,
Other,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilePart {
pub file_name: String,
pub size: u64,
pub url: String,
pub md5: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Media {
pub id: MediaId,
pub name: String,
pub kind: MediaKind,
pub size_original: u64,
pub time_unix: Option<i64>,
pub camera: Option<String>,
pub parts: Vec<FilePart>,
}
#[derive(Debug, Clone)]
pub struct MediaPage {
pub items: Vec<Media>,
pub total: Option<u64>,
pub next: Option<PageCursor>,
}
#[derive(Debug, Clone, Default)]
pub struct PageCursor {
pub page: u32,
pub count: u32,
}
impl PageCursor {
pub fn first(count: u32) -> Self {
PageCursor { page: 1, count }
}
pub fn next(&self) -> Self {
PageCursor {
page: self.page + 1,
count: self.count,
}
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct Profile {
#[serde(alias = "userId", alias = "ins_user_id")]
pub user_id: Option<String>,
#[serde(alias = "userEmail", alias = "email")]
pub email: Option<String>,
#[serde(alias = "userName", alias = "username", alias = "nickname")]
pub name: Option<String>,
}