Documentation
//! Provides the core types and impls for `yush`.

use serde::{Deserialize, Serialize};

/// This is to allow a [`Blob`] to distinguish between different kinds
/// of media
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
pub enum Kind {
    Video(Video),
}

/// A video
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
pub struct Video {
    /// The length of the video in seconds.
    pub len: f64,
}

/// An entry of metadata to some binary object.
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
pub struct Blob {
    /// The underlying target.
    pub filename: String,
    /// The path to the preview of the filename
    pub preview: String,
    /// The title of this work.
    pub title: String,
    /// The date of this work.
    // TODO use a timestamp, this is fine for a prototype.
    pub date: Option<String>,
    /// The size in bytes
    pub size: usize,
    /// The kind of this blob
    pub kind: Kind,
}

/// A newtype for a vector of blobs
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
pub struct Blobs {
    pub blobs: Vec<Blob>,
}

impl Kind {
    /// Convert this kind into a [`Video`]
    pub fn as_video(&self) -> Option<&Video> {
        match self {
            Self::Video(v) => Some(v),
        }
    }
}