module TD.Data.StoryAlbums
  (StoryAlbums(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.StoryAlbum as StoryAlbum

data StoryAlbums
  = StoryAlbums -- ^ Represents a list of story albums
    { StoryAlbums -> Maybe [StoryAlbum]
albums :: Maybe [StoryAlbum.StoryAlbum] -- ^ List of story albums
    }
  deriving (StoryAlbums -> StoryAlbums -> Bool
(StoryAlbums -> StoryAlbums -> Bool)
-> (StoryAlbums -> StoryAlbums -> Bool) -> Eq StoryAlbums
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StoryAlbums -> StoryAlbums -> Bool
== :: StoryAlbums -> StoryAlbums -> Bool
$c/= :: StoryAlbums -> StoryAlbums -> Bool
/= :: StoryAlbums -> StoryAlbums -> Bool
Eq, Int -> StoryAlbums -> ShowS
[StoryAlbums] -> ShowS
StoryAlbums -> String
(Int -> StoryAlbums -> ShowS)
-> (StoryAlbums -> String)
-> ([StoryAlbums] -> ShowS)
-> Show StoryAlbums
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StoryAlbums -> ShowS
showsPrec :: Int -> StoryAlbums -> ShowS
$cshow :: StoryAlbums -> String
show :: StoryAlbums -> String
$cshowList :: [StoryAlbums] -> ShowS
showList :: [StoryAlbums] -> ShowS
Show)

instance I.ShortShow StoryAlbums where
  shortShow :: StoryAlbums -> String
shortShow StoryAlbums
    { albums :: StoryAlbums -> Maybe [StoryAlbum]
albums = Maybe [StoryAlbum]
albums_
    }
      = String
"StoryAlbums"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"albums" String -> Maybe [StoryAlbum] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [StoryAlbum]
albums_
        ]

instance AT.FromJSON StoryAlbums where
  parseJSON :: Value -> Parser StoryAlbums
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"storyAlbums" -> Value -> Parser StoryAlbums
parseStoryAlbums Value
v
      String
_             -> Parser StoryAlbums
forall a. Monoid a => a
mempty
    
    where
      parseStoryAlbums :: A.Value -> AT.Parser StoryAlbums
      parseStoryAlbums :: Value -> Parser StoryAlbums
parseStoryAlbums = String
-> (Object -> Parser StoryAlbums) -> Value -> Parser StoryAlbums
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryAlbums" ((Object -> Parser StoryAlbums) -> Value -> Parser StoryAlbums)
-> (Object -> Parser StoryAlbums) -> Value -> Parser StoryAlbums
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [StoryAlbum]
albums_ <- Object
o Object -> Key -> Parser (Maybe [StoryAlbum])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"albums"
        StoryAlbums -> Parser StoryAlbums
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryAlbums -> Parser StoryAlbums)
-> StoryAlbums -> Parser StoryAlbums
forall a b. (a -> b) -> a -> b
$ StoryAlbums
          { albums :: Maybe [StoryAlbum]
albums = Maybe [StoryAlbum]
albums_
          }
  parseJSON Value
_ = Parser StoryAlbums
forall a. Monoid a => a
mempty