module TD.Data.Backgrounds
(Backgrounds(..)) 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.Background as Background
data Backgrounds
= Backgrounds
{ Backgrounds -> Maybe [Background]
backgrounds :: Maybe [Background.Background]
}
deriving (Backgrounds -> Backgrounds -> Bool
(Backgrounds -> Backgrounds -> Bool)
-> (Backgrounds -> Backgrounds -> Bool) -> Eq Backgrounds
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Backgrounds -> Backgrounds -> Bool
== :: Backgrounds -> Backgrounds -> Bool
$c/= :: Backgrounds -> Backgrounds -> Bool
/= :: Backgrounds -> Backgrounds -> Bool
Eq, Int -> Backgrounds -> ShowS
[Backgrounds] -> ShowS
Backgrounds -> String
(Int -> Backgrounds -> ShowS)
-> (Backgrounds -> String)
-> ([Backgrounds] -> ShowS)
-> Show Backgrounds
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Backgrounds -> ShowS
showsPrec :: Int -> Backgrounds -> ShowS
$cshow :: Backgrounds -> String
show :: Backgrounds -> String
$cshowList :: [Backgrounds] -> ShowS
showList :: [Backgrounds] -> ShowS
Show)
instance I.ShortShow Backgrounds where
shortShow :: Backgrounds -> String
shortShow Backgrounds
{ backgrounds :: Backgrounds -> Maybe [Background]
backgrounds = Maybe [Background]
backgrounds_
}
= String
"Backgrounds"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"backgrounds" String -> Maybe [Background] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Background]
backgrounds_
]
instance AT.FromJSON Backgrounds where
parseJSON :: Value -> Parser Backgrounds
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
"backgrounds" -> Value -> Parser Backgrounds
parseBackgrounds Value
v
String
_ -> Parser Backgrounds
forall a. Monoid a => a
mempty
where
parseBackgrounds :: A.Value -> AT.Parser Backgrounds
parseBackgrounds :: Value -> Parser Backgrounds
parseBackgrounds = String
-> (Object -> Parser Backgrounds) -> Value -> Parser Backgrounds
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Backgrounds" ((Object -> Parser Backgrounds) -> Value -> Parser Backgrounds)
-> (Object -> Parser Backgrounds) -> Value -> Parser Backgrounds
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [Background]
backgrounds_ <- Object
o Object -> Key -> Parser (Maybe [Background])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"backgrounds"
Backgrounds -> Parser Backgrounds
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Backgrounds -> Parser Backgrounds)
-> Backgrounds -> Parser Backgrounds
forall a b. (a -> b) -> a -> b
$ Backgrounds
{ backgrounds :: Maybe [Background]
backgrounds = Maybe [Background]
backgrounds_
}
parseJSON Value
_ = Parser Backgrounds
forall a. Monoid a => a
mempty