module TD.Data.GroupCallJoinParameters
  ( GroupCallJoinParameters(..)    
  , defaultGroupCallJoinParameters 
  ) where

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

data GroupCallJoinParameters
  = GroupCallJoinParameters -- ^ Describes parameters used to join a group call
    { GroupCallJoinParameters -> Maybe Int
audio_source_id     :: Maybe Int    -- ^ Audio channel synchronization source identifier; received from tgcalls
    , GroupCallJoinParameters -> Maybe Text
payload             :: Maybe T.Text -- ^ Group call join payload; received from tgcalls
    , GroupCallJoinParameters -> Maybe Bool
is_muted            :: Maybe Bool   -- ^ Pass true to join the call with muted microphone
    , GroupCallJoinParameters -> Maybe Bool
is_my_video_enabled :: Maybe Bool   -- ^ Pass true if the user's video is enabled
    }
  deriving (GroupCallJoinParameters -> GroupCallJoinParameters -> Bool
(GroupCallJoinParameters -> GroupCallJoinParameters -> Bool)
-> (GroupCallJoinParameters -> GroupCallJoinParameters -> Bool)
-> Eq GroupCallJoinParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GroupCallJoinParameters -> GroupCallJoinParameters -> Bool
== :: GroupCallJoinParameters -> GroupCallJoinParameters -> Bool
$c/= :: GroupCallJoinParameters -> GroupCallJoinParameters -> Bool
/= :: GroupCallJoinParameters -> GroupCallJoinParameters -> Bool
Eq, Int -> GroupCallJoinParameters -> ShowS
[GroupCallJoinParameters] -> ShowS
GroupCallJoinParameters -> String
(Int -> GroupCallJoinParameters -> ShowS)
-> (GroupCallJoinParameters -> String)
-> ([GroupCallJoinParameters] -> ShowS)
-> Show GroupCallJoinParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GroupCallJoinParameters -> ShowS
showsPrec :: Int -> GroupCallJoinParameters -> ShowS
$cshow :: GroupCallJoinParameters -> String
show :: GroupCallJoinParameters -> String
$cshowList :: [GroupCallJoinParameters] -> ShowS
showList :: [GroupCallJoinParameters] -> ShowS
Show)

instance I.ShortShow GroupCallJoinParameters where
  shortShow :: GroupCallJoinParameters -> String
shortShow GroupCallJoinParameters
    { audio_source_id :: GroupCallJoinParameters -> Maybe Int
audio_source_id     = Maybe Int
audio_source_id_
    , payload :: GroupCallJoinParameters -> Maybe Text
payload             = Maybe Text
payload_
    , is_muted :: GroupCallJoinParameters -> Maybe Bool
is_muted            = Maybe Bool
is_muted_
    , is_my_video_enabled :: GroupCallJoinParameters -> Maybe Bool
is_my_video_enabled = Maybe Bool
is_my_video_enabled_
    }
      = String
"GroupCallJoinParameters"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"audio_source_id"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
audio_source_id_
        , String
"payload"             String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
payload_
        , String
"is_muted"            String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_muted_
        , String
"is_my_video_enabled" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_my_video_enabled_
        ]

instance AT.FromJSON GroupCallJoinParameters where
  parseJSON :: Value -> Parser GroupCallJoinParameters
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
"groupCallJoinParameters" -> Value -> Parser GroupCallJoinParameters
parseGroupCallJoinParameters Value
v
      String
_                         -> Parser GroupCallJoinParameters
forall a. Monoid a => a
mempty
    
    where
      parseGroupCallJoinParameters :: A.Value -> AT.Parser GroupCallJoinParameters
      parseGroupCallJoinParameters :: Value -> Parser GroupCallJoinParameters
parseGroupCallJoinParameters = String
-> (Object -> Parser GroupCallJoinParameters)
-> Value
-> Parser GroupCallJoinParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"GroupCallJoinParameters" ((Object -> Parser GroupCallJoinParameters)
 -> Value -> Parser GroupCallJoinParameters)
-> (Object -> Parser GroupCallJoinParameters)
-> Value
-> Parser GroupCallJoinParameters
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
audio_source_id_     <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"audio_source_id"
        Maybe Text
payload_             <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"payload"
        Maybe Bool
is_muted_            <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_muted"
        Maybe Bool
is_my_video_enabled_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_my_video_enabled"
        GroupCallJoinParameters -> Parser GroupCallJoinParameters
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GroupCallJoinParameters -> Parser GroupCallJoinParameters)
-> GroupCallJoinParameters -> Parser GroupCallJoinParameters
forall a b. (a -> b) -> a -> b
$ GroupCallJoinParameters
          { audio_source_id :: Maybe Int
audio_source_id     = Maybe Int
audio_source_id_
          , payload :: Maybe Text
payload             = Maybe Text
payload_
          , is_muted :: Maybe Bool
is_muted            = Maybe Bool
is_muted_
          , is_my_video_enabled :: Maybe Bool
is_my_video_enabled = Maybe Bool
is_my_video_enabled_
          }
  parseJSON Value
_ = Parser GroupCallJoinParameters
forall a. Monoid a => a
mempty

instance AT.ToJSON GroupCallJoinParameters where
  toJSON :: GroupCallJoinParameters -> Value
toJSON GroupCallJoinParameters
    { audio_source_id :: GroupCallJoinParameters -> Maybe Int
audio_source_id     = Maybe Int
audio_source_id_
    , payload :: GroupCallJoinParameters -> Maybe Text
payload             = Maybe Text
payload_
    , is_muted :: GroupCallJoinParameters -> Maybe Bool
is_muted            = Maybe Bool
is_muted_
    , is_my_video_enabled :: GroupCallJoinParameters -> Maybe Bool
is_my_video_enabled = Maybe Bool
is_my_video_enabled_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"               Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"groupCallJoinParameters"
        , Key
"audio_source_id"     Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
audio_source_id_
        , Key
"payload"             Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
payload_
        , Key
"is_muted"            Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_muted_
        , Key
"is_my_video_enabled" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_my_video_enabled_
        ]

defaultGroupCallJoinParameters :: GroupCallJoinParameters
defaultGroupCallJoinParameters :: GroupCallJoinParameters
defaultGroupCallJoinParameters =
  GroupCallJoinParameters
    { audio_source_id :: Maybe Int
audio_source_id     = Maybe Int
forall a. Maybe a
Nothing
    , payload :: Maybe Text
payload             = Maybe Text
forall a. Maybe a
Nothing
    , is_muted :: Maybe Bool
is_muted            = Maybe Bool
forall a. Maybe a
Nothing
    , is_my_video_enabled :: Maybe Bool
is_my_video_enabled = Maybe Bool
forall a. Maybe a
Nothing
    }