entertainarr-adapter-http 0.1.0

HTTP adapter for entertainarr
Documentation
use std::collections::HashSet;

use chrono::{DateTime, NaiveDate, Utc};

use crate::entity::language::Language;
use crate::entity::prelude::{Page, Sort};
use crate::entity::tvshow::{TvShowDocument, TvShowEntity, TvShowSource};
use crate::entity::{Entity, Relation};

crate::create_kind!(TvShowSeasonKind, "tvshow-seasons");

pub type TvShowSeasonEntity = Entity<u64, TvShowSeasonKind>;

#[cfg_attr(feature = "facet", derive(facet::Facet))]
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TvShowSeasonDocument {
    pub id: u64,
    #[serde(rename = "type")]
    pub kind: TvShowSeasonKind,
    pub attributes: TvShowSeasonAttributes,
    pub relationships: TvShowSeasonRelationships,
}

#[cfg_attr(feature = "facet", derive(facet::Facet))]
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TvShowSeasonAttributes {
    pub source: TvShowSource,
    pub season_number: u64,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub air_date: Option<NaiveDate>,
    pub language: Language,
    pub name: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub overview: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub poster_url: Option<String>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[cfg_attr(feature = "facet", derive(facet::Facet))]
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TvShowSeasonRelationships {
    pub tvshow: Relation<TvShowEntity>,
}

#[cfg_attr(feature = "facet", derive(facet::Facet))]
#[cfg_attr(feature = "facet", repr(C))]
#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub enum TvShowSeasonField {
    #[default]
    SeasonNumber,
}

impl super::prelude::AsStr for TvShowSeasonField {
    fn as_str(&self) -> &str {
        match self {
            Self::SeasonNumber => "season_number",
        }
    }
}

impl std::str::FromStr for TvShowSeasonField {
    type Err = super::prelude::ParseEnumError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "season_number" => Ok(TvShowSeasonField::SeasonNumber),
            other => Err(super::prelude::ParseEnumError::new(other)),
        }
    }
}

#[cfg_attr(feature = "facet", derive(facet::Facet))]
#[cfg_attr(feature = "facet", repr(C))]
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase", untagged)]
pub enum TvShowSeasonRelation {
    TvShow(TvShowDocument),
}

#[cfg_attr(feature = "facet", derive(facet::Facet))]
#[cfg_attr(feature = "facet", repr(C))]
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum TvShowSeasonInclude {
    #[default]
    #[serde(rename = "tvshow")]
    TvShow,
}

#[cfg_attr(feature = "facet", derive(facet::Facet))]
#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ListTvShowSeasonParams {
    #[serde(default, skip_serializing_if = "HashSet::is_empty")]
    pub include: HashSet<TvShowSeasonInclude>,
    #[serde(default, skip_serializing_if = "Sort::is_default")]
    pub sort: Sort<TvShowSeasonField>,
    #[serde(default, skip_serializing_if = "Page::is_default")]
    pub page: Page,
}

impl ListTvShowSeasonParams {
    pub fn include(mut self, item: TvShowSeasonInclude) -> Self {
        self.include.insert(item);
        self
    }
}