module TD.Data.Animations
  (Animations(..)) 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.Animation as Animation

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

instance I.ShortShow Animations where
  shortShow :: Animations -> String
shortShow Animations
    { animations :: Animations -> Maybe [Animation]
animations = Maybe [Animation]
animations_
    }
      = String
"Animations"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"animations" String -> Maybe [Animation] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Animation]
animations_
        ]

instance AT.FromJSON Animations where
  parseJSON :: Value -> Parser Animations
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
"animations" -> Value -> Parser Animations
parseAnimations Value
v
      String
_            -> Parser Animations
forall a. Monoid a => a
mempty
    
    where
      parseAnimations :: A.Value -> AT.Parser Animations
      parseAnimations :: Value -> Parser Animations
parseAnimations = String
-> (Object -> Parser Animations) -> Value -> Parser Animations
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Animations" ((Object -> Parser Animations) -> Value -> Parser Animations)
-> (Object -> Parser Animations) -> Value -> Parser Animations
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [Animation]
animations_ <- Object
o Object -> Key -> Parser (Maybe [Animation])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"animations"
        Animations -> Parser Animations
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Animations -> Parser Animations)
-> Animations -> Parser Animations
forall a b. (a -> b) -> a -> b
$ Animations
          { animations :: Maybe [Animation]
animations = Maybe [Animation]
animations_
          }
  parseJSON Value
_ = Parser Animations
forall a. Monoid a => a
mempty