module TD.Data.AvailableGifts
  (AvailableGifts(..)) 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.AvailableGift as AvailableGift

data AvailableGifts
  = AvailableGifts -- ^ Contains a list of gifts that can be sent to another user or channel chat
    { AvailableGifts -> Maybe [AvailableGift]
gifts :: Maybe [AvailableGift.AvailableGift] -- ^ The list of gifts
    }
  deriving (AvailableGifts -> AvailableGifts -> Bool
(AvailableGifts -> AvailableGifts -> Bool)
-> (AvailableGifts -> AvailableGifts -> Bool) -> Eq AvailableGifts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AvailableGifts -> AvailableGifts -> Bool
== :: AvailableGifts -> AvailableGifts -> Bool
$c/= :: AvailableGifts -> AvailableGifts -> Bool
/= :: AvailableGifts -> AvailableGifts -> Bool
Eq, Int -> AvailableGifts -> ShowS
[AvailableGifts] -> ShowS
AvailableGifts -> String
(Int -> AvailableGifts -> ShowS)
-> (AvailableGifts -> String)
-> ([AvailableGifts] -> ShowS)
-> Show AvailableGifts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AvailableGifts -> ShowS
showsPrec :: Int -> AvailableGifts -> ShowS
$cshow :: AvailableGifts -> String
show :: AvailableGifts -> String
$cshowList :: [AvailableGifts] -> ShowS
showList :: [AvailableGifts] -> ShowS
Show)

instance I.ShortShow AvailableGifts where
  shortShow :: AvailableGifts -> String
shortShow AvailableGifts
    { gifts :: AvailableGifts -> Maybe [AvailableGift]
gifts = Maybe [AvailableGift]
gifts_
    }
      = String
"AvailableGifts"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"gifts" String -> Maybe [AvailableGift] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [AvailableGift]
gifts_
        ]

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