module TD.Data.InviteGroupCallParticipantResult
  (InviteGroupCallParticipantResult(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

-- | Describes result of group call participant invitation
data InviteGroupCallParticipantResult
  = InviteGroupCallParticipantResultUserPrivacyRestricted -- ^ The user can't be invited due to their privacy settings
  | InviteGroupCallParticipantResultUserAlreadyParticipant -- ^ The user can't be invited because they are already a participant of the call
  | InviteGroupCallParticipantResultUserWasBanned -- ^ The user can't be invited because they were banned by the owner of the call and can be invited back only by the owner of the group call
  | InviteGroupCallParticipantResultSuccess -- ^ The user was invited and a service message of the type messageGroupCall was sent which can be used in declineGroupCallInvitation to cancel the invitation
    { InviteGroupCallParticipantResult -> Maybe Int
chat_id    :: Maybe Int -- ^ Identifier of the chat with the invitation message
    , InviteGroupCallParticipantResult -> Maybe Int
message_id :: Maybe Int -- ^ Identifier of the message
    }
  deriving (InviteGroupCallParticipantResult
-> InviteGroupCallParticipantResult -> Bool
(InviteGroupCallParticipantResult
 -> InviteGroupCallParticipantResult -> Bool)
-> (InviteGroupCallParticipantResult
    -> InviteGroupCallParticipantResult -> Bool)
-> Eq InviteGroupCallParticipantResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InviteGroupCallParticipantResult
-> InviteGroupCallParticipantResult -> Bool
== :: InviteGroupCallParticipantResult
-> InviteGroupCallParticipantResult -> Bool
$c/= :: InviteGroupCallParticipantResult
-> InviteGroupCallParticipantResult -> Bool
/= :: InviteGroupCallParticipantResult
-> InviteGroupCallParticipantResult -> Bool
Eq, Int -> InviteGroupCallParticipantResult -> ShowS
[InviteGroupCallParticipantResult] -> ShowS
InviteGroupCallParticipantResult -> String
(Int -> InviteGroupCallParticipantResult -> ShowS)
-> (InviteGroupCallParticipantResult -> String)
-> ([InviteGroupCallParticipantResult] -> ShowS)
-> Show InviteGroupCallParticipantResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InviteGroupCallParticipantResult -> ShowS
showsPrec :: Int -> InviteGroupCallParticipantResult -> ShowS
$cshow :: InviteGroupCallParticipantResult -> String
show :: InviteGroupCallParticipantResult -> String
$cshowList :: [InviteGroupCallParticipantResult] -> ShowS
showList :: [InviteGroupCallParticipantResult] -> ShowS
Show)

instance I.ShortShow InviteGroupCallParticipantResult where
  shortShow :: InviteGroupCallParticipantResult -> String
shortShow InviteGroupCallParticipantResult
InviteGroupCallParticipantResultUserPrivacyRestricted
      = String
"InviteGroupCallParticipantResultUserPrivacyRestricted"
  shortShow InviteGroupCallParticipantResult
InviteGroupCallParticipantResultUserAlreadyParticipant
      = String
"InviteGroupCallParticipantResultUserAlreadyParticipant"
  shortShow InviteGroupCallParticipantResult
InviteGroupCallParticipantResultUserWasBanned
      = String
"InviteGroupCallParticipantResultUserWasBanned"
  shortShow InviteGroupCallParticipantResultSuccess
    { chat_id :: InviteGroupCallParticipantResult -> Maybe Int
chat_id    = Maybe Int
chat_id_
    , message_id :: InviteGroupCallParticipantResult -> Maybe Int
message_id = Maybe Int
message_id_
    }
      = String
"InviteGroupCallParticipantResultSuccess"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"chat_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
        , String
"message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
        ]

instance AT.FromJSON InviteGroupCallParticipantResult where
  parseJSON :: Value -> Parser InviteGroupCallParticipantResult
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
"inviteGroupCallParticipantResultUserPrivacyRestricted"  -> InviteGroupCallParticipantResult
-> Parser InviteGroupCallParticipantResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InviteGroupCallParticipantResult
InviteGroupCallParticipantResultUserPrivacyRestricted
      String
"inviteGroupCallParticipantResultUserAlreadyParticipant" -> InviteGroupCallParticipantResult
-> Parser InviteGroupCallParticipantResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InviteGroupCallParticipantResult
InviteGroupCallParticipantResultUserAlreadyParticipant
      String
"inviteGroupCallParticipantResultUserWasBanned"          -> InviteGroupCallParticipantResult
-> Parser InviteGroupCallParticipantResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InviteGroupCallParticipantResult
InviteGroupCallParticipantResultUserWasBanned
      String
"inviteGroupCallParticipantResultSuccess"                -> Value -> Parser InviteGroupCallParticipantResult
parseInviteGroupCallParticipantResultSuccess Value
v
      String
_                                                        -> Parser InviteGroupCallParticipantResult
forall a. Monoid a => a
mempty
    
    where
      parseInviteGroupCallParticipantResultSuccess :: A.Value -> AT.Parser InviteGroupCallParticipantResult
      parseInviteGroupCallParticipantResultSuccess :: Value -> Parser InviteGroupCallParticipantResult
parseInviteGroupCallParticipantResultSuccess = String
-> (Object -> Parser InviteGroupCallParticipantResult)
-> Value
-> Parser InviteGroupCallParticipantResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InviteGroupCallParticipantResultSuccess" ((Object -> Parser InviteGroupCallParticipantResult)
 -> Value -> Parser InviteGroupCallParticipantResult)
-> (Object -> Parser InviteGroupCallParticipantResult)
-> Value
-> Parser InviteGroupCallParticipantResult
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
chat_id_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_id"
        Maybe Int
message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"message_id"
        InviteGroupCallParticipantResult
-> Parser InviteGroupCallParticipantResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InviteGroupCallParticipantResult
 -> Parser InviteGroupCallParticipantResult)
-> InviteGroupCallParticipantResult
-> Parser InviteGroupCallParticipantResult
forall a b. (a -> b) -> a -> b
$ InviteGroupCallParticipantResultSuccess
          { chat_id :: Maybe Int
chat_id    = Maybe Int
chat_id_
          , message_id :: Maybe Int
message_id = Maybe Int
message_id_
          }
  parseJSON Value
_ = Parser InviteGroupCallParticipantResult
forall a. Monoid a => a
mempty