module TD.Data.VideoChat
  (VideoChat(..)) 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 VideoChat
  = VideoChat -- ^ Describes a video chat
    { VideoChat -> Maybe Int
group_call_id          :: Maybe Int                         -- ^ Group call identifier of an active video chat; 0 if none. Full information about the video chat can be received through the method getGroupCall
    , VideoChat -> Maybe Bool
has_participants       :: Maybe Bool                        -- ^ True, if the video chat has participants
    , VideoChat -> Maybe MessageSender
default_participant_id :: Maybe MessageSender.MessageSender -- ^ Default group call participant identifier to join the video chat; may be null
    }
  deriving (VideoChat -> VideoChat -> Bool
(VideoChat -> VideoChat -> Bool)
-> (VideoChat -> VideoChat -> Bool) -> Eq VideoChat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VideoChat -> VideoChat -> Bool
== :: VideoChat -> VideoChat -> Bool
$c/= :: VideoChat -> VideoChat -> Bool
/= :: VideoChat -> VideoChat -> Bool
Eq, Int -> VideoChat -> ShowS
[VideoChat] -> ShowS
VideoChat -> String
(Int -> VideoChat -> ShowS)
-> (VideoChat -> String)
-> ([VideoChat] -> ShowS)
-> Show VideoChat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VideoChat -> ShowS
showsPrec :: Int -> VideoChat -> ShowS
$cshow :: VideoChat -> String
show :: VideoChat -> String
$cshowList :: [VideoChat] -> ShowS
showList :: [VideoChat] -> ShowS
Show)

instance I.ShortShow VideoChat where
  shortShow :: VideoChat -> String
shortShow VideoChat
    { group_call_id :: VideoChat -> Maybe Int
group_call_id          = Maybe Int
group_call_id_
    , has_participants :: VideoChat -> Maybe Bool
has_participants       = Maybe Bool
has_participants_
    , default_participant_id :: VideoChat -> Maybe MessageSender
default_participant_id = Maybe MessageSender
default_participant_id_
    }
      = String
"VideoChat"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"group_call_id"          String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
group_call_id_
        , String
"has_participants"       String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_participants_
        , String
"default_participant_id" String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
default_participant_id_
        ]

instance AT.FromJSON VideoChat where
  parseJSON :: Value -> Parser VideoChat
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
"videoChat" -> Value -> Parser VideoChat
parseVideoChat Value
v
      String
_           -> Parser VideoChat
forall a. Monoid a => a
mempty
    
    where
      parseVideoChat :: A.Value -> AT.Parser VideoChat
      parseVideoChat :: Value -> Parser VideoChat
parseVideoChat = String -> (Object -> Parser VideoChat) -> Value -> Parser VideoChat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"VideoChat" ((Object -> Parser VideoChat) -> Value -> Parser VideoChat)
-> (Object -> Parser VideoChat) -> Value -> Parser VideoChat
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
group_call_id_          <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"group_call_id"
        Maybe Bool
has_participants_       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"has_participants"
        Maybe MessageSender
default_participant_id_ <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"default_participant_id"
        VideoChat -> Parser VideoChat
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VideoChat -> Parser VideoChat) -> VideoChat -> Parser VideoChat
forall a b. (a -> b) -> a -> b
$ VideoChat
          { group_call_id :: Maybe Int
group_call_id          = Maybe Int
group_call_id_
          , has_participants :: Maybe Bool
has_participants       = Maybe Bool
has_participants_
          , default_participant_id :: Maybe MessageSender
default_participant_id = Maybe MessageSender
default_participant_id_
          }
  parseJSON Value
_ = Parser VideoChat
forall a. Monoid a => a
mempty