module TD.Data.GroupCallParticipants
  (GroupCallParticipants(..)) 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.MessageSender as MessageSender

data GroupCallParticipants
  = GroupCallParticipants -- ^ Contains identifiers of group call participants
    { GroupCallParticipants -> Maybe Int
total_count     :: Maybe Int                           -- ^ Total number of group call participants
    , GroupCallParticipants -> Maybe [MessageSender]
participant_ids :: Maybe [MessageSender.MessageSender] -- ^ Identifiers of the participants
    }
  deriving (GroupCallParticipants -> GroupCallParticipants -> Bool
(GroupCallParticipants -> GroupCallParticipants -> Bool)
-> (GroupCallParticipants -> GroupCallParticipants -> Bool)
-> Eq GroupCallParticipants
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GroupCallParticipants -> GroupCallParticipants -> Bool
== :: GroupCallParticipants -> GroupCallParticipants -> Bool
$c/= :: GroupCallParticipants -> GroupCallParticipants -> Bool
/= :: GroupCallParticipants -> GroupCallParticipants -> Bool
Eq, Int -> GroupCallParticipants -> ShowS
[GroupCallParticipants] -> ShowS
GroupCallParticipants -> String
(Int -> GroupCallParticipants -> ShowS)
-> (GroupCallParticipants -> String)
-> ([GroupCallParticipants] -> ShowS)
-> Show GroupCallParticipants
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GroupCallParticipants -> ShowS
showsPrec :: Int -> GroupCallParticipants -> ShowS
$cshow :: GroupCallParticipants -> String
show :: GroupCallParticipants -> String
$cshowList :: [GroupCallParticipants] -> ShowS
showList :: [GroupCallParticipants] -> ShowS
Show)

instance I.ShortShow GroupCallParticipants where
  shortShow :: GroupCallParticipants -> String
shortShow GroupCallParticipants
    { total_count :: GroupCallParticipants -> Maybe Int
total_count     = Maybe Int
total_count_
    , participant_ids :: GroupCallParticipants -> Maybe [MessageSender]
participant_ids = Maybe [MessageSender]
participant_ids_
    }
      = String
"GroupCallParticipants"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"total_count"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
        , String
"participant_ids" String -> Maybe [MessageSender] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [MessageSender]
participant_ids_
        ]

instance AT.FromJSON GroupCallParticipants where
  parseJSON :: Value -> Parser GroupCallParticipants
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
"groupCallParticipants" -> Value -> Parser GroupCallParticipants
parseGroupCallParticipants Value
v
      String
_                       -> Parser GroupCallParticipants
forall a. Monoid a => a
mempty
    
    where
      parseGroupCallParticipants :: A.Value -> AT.Parser GroupCallParticipants
      parseGroupCallParticipants :: Value -> Parser GroupCallParticipants
parseGroupCallParticipants = String
-> (Object -> Parser GroupCallParticipants)
-> Value
-> Parser GroupCallParticipants
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GroupCallParticipants" ((Object -> Parser GroupCallParticipants)
 -> Value -> Parser GroupCallParticipants)
-> (Object -> Parser GroupCallParticipants)
-> Value
-> Parser GroupCallParticipants
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
total_count_     <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"total_count"
        Maybe [MessageSender]
participant_ids_ <- Object
o Object -> Key -> Parser (Maybe [MessageSender])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"participant_ids"
        GroupCallParticipants -> Parser GroupCallParticipants
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GroupCallParticipants -> Parser GroupCallParticipants)
-> GroupCallParticipants -> Parser GroupCallParticipants
forall a b. (a -> b) -> a -> b
$ GroupCallParticipants
          { total_count :: Maybe Int
total_count     = Maybe Int
total_count_
          , participant_ids :: Maybe [MessageSender]
participant_ids = Maybe [MessageSender]
participant_ids_
          }
  parseJSON Value
_ = Parser GroupCallParticipants
forall a. Monoid a => a
mempty