module Network.API.TheMovieDB.Types.TV
( TV (..),
tvPosterURLs,
)
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.Genre
import Network.API.TheMovieDB.Types.Season
data TV = TV
{
TV -> ItemID
tvID :: ItemID,
TV -> Text
tvName :: Text,
TV -> Text
tvOverview :: Text,
TV -> [Genre]
tvGenres :: [Genre],
TV -> Double
tvPopularity :: Double,
TV -> Text
tvPosterPath :: Text,
TV -> Maybe Day
tvFirstAirDate :: Maybe Day,
TV -> Maybe Day
tvLastAirDate :: Maybe Day,
TV -> ItemID
tvNumberOfSeasons :: Int,
TV -> ItemID
tvNumberOfEpisodes :: Int,
TV -> [Season]
tvSeasons :: [Season]
}
deriving (TV -> TV -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TV -> TV -> Bool
$c/= :: TV -> TV -> Bool
== :: TV -> TV -> Bool
$c== :: TV -> TV -> Bool
Eq, ItemID -> TV -> ShowS
[TV] -> ShowS
TV -> String
forall a.
(ItemID -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TV] -> ShowS
$cshowList :: [TV] -> ShowS
show :: TV -> String
$cshow :: TV -> String
showsPrec :: ItemID -> TV -> ShowS
$cshowsPrec :: ItemID -> TV -> ShowS
Show)
instance Ord TV where
compare :: TV -> TV -> Ordering
compare TV
a TV
b = TV -> ItemID
tvID TV
a forall a. Ord a => a -> a -> Ordering
`compare` TV -> ItemID
tvID TV
b
instance FromJSON TV where
parseJSON :: Value -> Parser TV
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TV" forall a b. (a -> b) -> a -> b
$ \Object
v ->
ItemID
-> Text
-> Text
-> [Genre]
-> Double
-> Text
-> Maybe Day
-> Maybe Day
-> ItemID
-> ItemID
-> [Season]
-> TV
TV
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
"name"
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
"overview" 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
"genres" forall a. Parser (Maybe a) -> a -> Parser a
.!= []
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
"popularity" forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0.0
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
"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 Object -> Key -> Parser (Maybe Day)
.:: Key
"first_air_date"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Day)
.:: Key
"last_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
"number_of_seasons" 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 (Maybe a)
.:? Key
"number_of_episodes" 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 (Maybe a)
.:? Key
"seasons" forall a. Parser (Maybe a) -> a -> Parser a
.!= []
tvPosterURLs :: Configuration -> TV -> [Text]
tvPosterURLs :: Configuration -> TV -> [Text]
tvPosterURLs Configuration
c TV
m = Configuration -> Text -> [Text]
posterURLs Configuration
c (TV -> Text
tvPosterPath TV
m)