use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum PaidMedia {
Preview(crate::types::PaidMediaPreview),
Photo(crate::types::PaidMediaPhoto),
Video(crate::types::PaidMediaVideo),
}
impl PaidMedia {
#[must_use]
pub fn duration(&self) -> Option<i64> {
match self {
Self::Preview(val) => val.duration,
_ => None,
}
}
#[must_use]
pub fn height(&self) -> Option<i64> {
match self {
Self::Preview(val) => val.height,
_ => None,
}
}
#[must_use]
pub fn photo(&self) -> Option<&[crate::types::PhotoSize]> {
match self {
Self::Photo(val) => Some(val.photo.as_ref()),
_ => None,
}
}
#[must_use]
pub fn video(&self) -> Option<&crate::types::Video> {
match self {
Self::Video(val) => Some(val.video.as_ref()),
_ => None,
}
}
#[must_use]
pub fn width(&self) -> Option<i64> {
match self {
Self::Preview(val) => val.width,
_ => None,
}
}
#[must_use]
pub fn cover(&self) -> Option<&[crate::types::PhotoSize]> {
match self {
Self::Video(val) => {
let inner = val.video.as_ref();
inner.cover.as_deref()
}
_ => None,
}
}
#[must_use]
pub fn file_id(&self) -> Option<&str> {
match self {
Self::Video(val) => {
let inner = val.video.as_ref();
Some(inner.file_id.as_ref())
}
_ => None,
}
}
#[must_use]
pub fn file_name(&self) -> Option<&str> {
match self {
Self::Video(val) => {
let inner = val.video.as_ref();
inner.file_name.as_deref()
}
_ => None,
}
}
#[must_use]
pub fn file_size(&self) -> Option<i64> {
match self {
Self::Video(val) => {
let inner = val.video.as_ref();
inner.file_size
}
_ => None,
}
}
#[must_use]
pub fn file_unique_id(&self) -> Option<&str> {
match self {
Self::Video(val) => {
let inner = val.video.as_ref();
Some(inner.file_unique_id.as_ref())
}
_ => None,
}
}
#[must_use]
pub fn mime_type(&self) -> Option<&str> {
match self {
Self::Video(val) => {
let inner = val.video.as_ref();
inner.mime_type.as_deref()
}
_ => None,
}
}
#[must_use]
pub fn qualities(&self) -> Option<&[crate::types::VideoQuality]> {
match self {
Self::Video(val) => {
let inner = val.video.as_ref();
inner.qualities.as_deref()
}
_ => None,
}
}
#[must_use]
pub fn start_timestamp(&self) -> Option<i64> {
match self {
Self::Video(val) => {
let inner = val.video.as_ref();
inner.start_timestamp
}
_ => None,
}
}
#[must_use]
pub fn thumbnail(&self) -> Option<&crate::types::PhotoSize> {
match self {
Self::Video(val) => {
let inner = val.video.as_ref();
inner.thumbnail.as_ref()
}
_ => None,
}
}
}
impl From<crate::types::PaidMediaPreview> for PaidMedia {
fn from(val: crate::types::PaidMediaPreview) -> Self {
Self::Preview(val)
}
}
impl TryFrom<PaidMedia> for crate::types::PaidMediaPreview {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: PaidMedia) -> Result<Self, Self::Error> {
if let PaidMedia::Preview(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(PaidMedia),
stringify!(PaidMediaPreview),
))
}
}
}
impl From<crate::types::PaidMediaPhoto> for PaidMedia {
fn from(val: crate::types::PaidMediaPhoto) -> Self {
Self::Photo(val)
}
}
impl TryFrom<PaidMedia> for crate::types::PaidMediaPhoto {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: PaidMedia) -> Result<Self, Self::Error> {
if let PaidMedia::Photo(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(PaidMedia),
stringify!(PaidMediaPhoto),
))
}
}
}
impl From<crate::types::PaidMediaVideo> for PaidMedia {
fn from(val: crate::types::PaidMediaVideo) -> Self {
Self::Video(val)
}
}
impl TryFrom<PaidMedia> for crate::types::PaidMediaVideo {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: PaidMedia) -> Result<Self, Self::Error> {
if let PaidMedia::Video(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(PaidMedia),
stringify!(PaidMediaVideo),
))
}
}
}