module TD.Data.ChatInviteLinkCounts
  (ChatInviteLinkCounts(..)) 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.ChatInviteLinkCount as ChatInviteLinkCount

data ChatInviteLinkCounts
  = ChatInviteLinkCounts -- ^ Contains a list of chat invite link counts
    { ChatInviteLinkCounts -> Maybe [ChatInviteLinkCount]
invite_link_counts :: Maybe [ChatInviteLinkCount.ChatInviteLinkCount] -- ^ List of invite link counts
    }
  deriving (ChatInviteLinkCounts -> ChatInviteLinkCounts -> Bool
(ChatInviteLinkCounts -> ChatInviteLinkCounts -> Bool)
-> (ChatInviteLinkCounts -> ChatInviteLinkCounts -> Bool)
-> Eq ChatInviteLinkCounts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatInviteLinkCounts -> ChatInviteLinkCounts -> Bool
== :: ChatInviteLinkCounts -> ChatInviteLinkCounts -> Bool
$c/= :: ChatInviteLinkCounts -> ChatInviteLinkCounts -> Bool
/= :: ChatInviteLinkCounts -> ChatInviteLinkCounts -> Bool
Eq, Int -> ChatInviteLinkCounts -> ShowS
[ChatInviteLinkCounts] -> ShowS
ChatInviteLinkCounts -> String
(Int -> ChatInviteLinkCounts -> ShowS)
-> (ChatInviteLinkCounts -> String)
-> ([ChatInviteLinkCounts] -> ShowS)
-> Show ChatInviteLinkCounts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatInviteLinkCounts -> ShowS
showsPrec :: Int -> ChatInviteLinkCounts -> ShowS
$cshow :: ChatInviteLinkCounts -> String
show :: ChatInviteLinkCounts -> String
$cshowList :: [ChatInviteLinkCounts] -> ShowS
showList :: [ChatInviteLinkCounts] -> ShowS
Show)

instance I.ShortShow ChatInviteLinkCounts where
  shortShow :: ChatInviteLinkCounts -> String
shortShow ChatInviteLinkCounts
    { invite_link_counts :: ChatInviteLinkCounts -> Maybe [ChatInviteLinkCount]
invite_link_counts = Maybe [ChatInviteLinkCount]
invite_link_counts_
    }
      = String
"ChatInviteLinkCounts"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"invite_link_counts" String -> Maybe [ChatInviteLinkCount] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [ChatInviteLinkCount]
invite_link_counts_
        ]

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