use std::fmt::{Display, Formatter, Result as FmtResult};
use chrono::{DateTime, FixedOffset};
use serde::{Deserialize, Serialize};
use crate::types::{UserId, VideoId};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Video {
pub id: VideoId,
pub stream_id: Option<String>,
pub user_id: UserId,
pub user_login: String,
pub user_name: String,
pub title: String,
pub description: String,
pub created_at: DateTime<FixedOffset>,
pub published_at: DateTime<FixedOffset>,
pub url: String,
pub thumbnail_url: String,
pub viewable: String,
pub view_count: u64,
pub language: String,
#[serde(rename = "type")]
pub kind: Type,
pub duration: String,
pub muted_segments: Vec<MutedSegment>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MutedSegment {
pub duration: u64,
pub offset: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Period {
All,
Day,
Month,
Week,
}
impl Period {
pub fn as_str(&self) -> &str {
match self {
Self::All => "all",
Self::Day => "day",
Self::Month => "month",
Self::Week => "week",
}
}
}
impl Display for Period {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.write_str(self.as_str())
}
}
impl AsRef<str> for Period {
fn as_ref(&self) -> &str {
self.as_str()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Sort {
Time,
Trending,
Views,
}
impl Sort {
pub fn as_str(&self) -> &str {
match self {
Self::Time => "time",
Self::Trending => "trending",
Self::Views => "views",
}
}
}
impl AsRef<str> for Sort {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl Display for Sort {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Type {
All,
Archive,
Highlight,
Upload,
}
impl Type {
pub fn as_str(&self) -> &str {
match self {
Self::All => "all",
Self::Archive => "archive",
Self::Highlight => "highlight",
Self::Upload => "upload",
}
}
}
impl AsRef<str> for Type {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl Display for Type {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.write_str(self.as_str())
}
}