module TD.Data.ChatBoostSlots
  (ChatBoostSlots(..)) 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.ChatBoostSlot as ChatBoostSlot

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

instance I.ShortShow ChatBoostSlots where
  shortShow :: ChatBoostSlots -> String
shortShow ChatBoostSlots
    { slots :: ChatBoostSlots -> Maybe [ChatBoostSlot]
slots = Maybe [ChatBoostSlot]
slots_
    }
      = String
"ChatBoostSlots"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"slots" String -> Maybe [ChatBoostSlot] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [ChatBoostSlot]
slots_
        ]

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