module TD.Data.GiftCollections
  (GiftCollections(..)) 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.GiftCollection as GiftCollection

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

instance I.ShortShow GiftCollections where
  shortShow :: GiftCollections -> String
shortShow GiftCollections
    { collections :: GiftCollections -> Maybe [GiftCollection]
collections = Maybe [GiftCollection]
collections_
    }
      = String
"GiftCollections"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"collections" String -> Maybe [GiftCollection] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [GiftCollection]
collections_
        ]

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