module Network.API.TheMovieDB.Types.Season
( Season (..),
seasonPosterURLs,
)
where
import Data.Aeson
import Data.Time (Day (..))
import Network.API.TheMovieDB.Internal.Configuration
import Network.API.TheMovieDB.Internal.Date
import Network.API.TheMovieDB.Internal.Types
import Network.API.TheMovieDB.Types.Episode
data Season = Season
{
Season -> ItemID
seasonID :: ItemID,
Season -> ItemID
seasonNumber :: Int,
Season -> Maybe Day
seasonAirDate :: Maybe Day,
Season -> ItemID
seasonEpisodeCount :: Int,
Season -> Text
seasonPosterPath :: Text,
Season -> [Episode]
seasonEpisodes :: [Episode]
}
deriving (Season -> Season -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Season -> Season -> Bool
$c/= :: Season -> Season -> Bool
== :: Season -> Season -> Bool
$c== :: Season -> Season -> Bool
Eq, ItemID -> Season -> ShowS
[Season] -> ShowS
Season -> String
forall a.
(ItemID -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Season] -> ShowS
$cshowList :: [Season] -> ShowS
show :: Season -> String
$cshow :: Season -> String
showsPrec :: ItemID -> Season -> ShowS
$cshowsPrec :: ItemID -> Season -> ShowS
Show)
instance Ord Season where
compare :: Season -> Season -> Ordering
compare Season
a Season
b = Season -> ItemID
seasonNumber Season
a forall a. Ord a => a -> a -> Ordering
`compare` Season -> ItemID
seasonNumber Season
b
instance FromJSON Season where
parseJSON :: Value -> Parser Season
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Season" forall a b. (a -> b) -> a -> b
$ \Object
v ->
ItemID
-> ItemID -> Maybe Day -> ItemID -> Text -> [Episode] -> Season
Season
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"season_number" forall a. Parser (Maybe a) -> a -> Parser a
.!= ItemID
0
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Day)
.:: Key
"air_date"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"episode_count" forall a. Parser (Maybe a) -> a -> Parser a
.!= ItemID
0
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"poster_path" forall a. Parser (Maybe a) -> a -> Parser a
.!= Text
""
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"episodes" forall a. Parser (Maybe a) -> a -> Parser a
.!= []
seasonPosterURLs :: Configuration -> Season -> [Text]
seasonPosterURLs :: Configuration -> Season -> [Text]
seasonPosterURLs Configuration
c Season
s = Configuration -> Text -> [Text]
posterURLs Configuration
c (Season -> Text
seasonPosterPath Season
s)