use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum BackgroundFill {
Solid(crate::types::BackgroundFillSolid),
Gradient(crate::types::BackgroundFillGradient),
FreeformGradient(crate::types::BackgroundFillFreeformGradient),
}
impl BackgroundFill {
#[must_use]
pub fn bottom_color(&self) -> Option<i64> {
match self {
Self::Gradient(val) => Some(val.bottom_color),
_ => None,
}
}
#[must_use]
pub fn color(&self) -> Option<i64> {
match self {
Self::Solid(val) => Some(val.color),
_ => None,
}
}
#[must_use]
pub fn colors(&self) -> Option<&[i64]> {
match self {
Self::FreeformGradient(val) => Some(val.colors.as_ref()),
_ => None,
}
}
#[must_use]
pub fn rotation_angle(&self) -> Option<u16> {
match self {
Self::Gradient(val) => Some(val.rotation_angle),
_ => None,
}
}
#[must_use]
pub fn top_color(&self) -> Option<i64> {
match self {
Self::Gradient(val) => Some(val.top_color),
_ => None,
}
}
}
impl From<crate::types::BackgroundFillSolid> for BackgroundFill {
fn from(val: crate::types::BackgroundFillSolid) -> Self {
Self::Solid(val)
}
}
impl TryFrom<BackgroundFill> for crate::types::BackgroundFillSolid {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: BackgroundFill) -> Result<Self, Self::Error> {
if let BackgroundFill::Solid(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(BackgroundFill),
stringify!(BackgroundFillSolid),
))
}
}
}
impl From<crate::types::BackgroundFillGradient> for BackgroundFill {
fn from(val: crate::types::BackgroundFillGradient) -> Self {
Self::Gradient(val)
}
}
impl TryFrom<BackgroundFill> for crate::types::BackgroundFillGradient {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: BackgroundFill) -> Result<Self, Self::Error> {
if let BackgroundFill::Gradient(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(BackgroundFill),
stringify!(BackgroundFillGradient),
))
}
}
}
impl From<crate::types::BackgroundFillFreeformGradient> for BackgroundFill {
fn from(val: crate::types::BackgroundFillFreeformGradient) -> Self {
Self::FreeformGradient(val)
}
}
impl TryFrom<BackgroundFill> for crate::types::BackgroundFillFreeformGradient {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: BackgroundFill) -> Result<Self, Self::Error> {
if let BackgroundFill::FreeformGradient(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(BackgroundFill),
stringify!(BackgroundFillFreeformGradient),
))
}
}
}