module TD.Data.GroupCallDataChannel
  (GroupCallDataChannel(..)) where

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

-- | Describes data channel for a group call
data GroupCallDataChannel
  = GroupCallDataChannelMain -- ^ The main data channel for audio and video data
  | GroupCallDataChannelScreenSharing -- ^ The data channel for screen sharing
  deriving (GroupCallDataChannel -> GroupCallDataChannel -> Bool
(GroupCallDataChannel -> GroupCallDataChannel -> Bool)
-> (GroupCallDataChannel -> GroupCallDataChannel -> Bool)
-> Eq GroupCallDataChannel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GroupCallDataChannel -> GroupCallDataChannel -> Bool
== :: GroupCallDataChannel -> GroupCallDataChannel -> Bool
$c/= :: GroupCallDataChannel -> GroupCallDataChannel -> Bool
/= :: GroupCallDataChannel -> GroupCallDataChannel -> Bool
Eq, Int -> GroupCallDataChannel -> ShowS
[GroupCallDataChannel] -> ShowS
GroupCallDataChannel -> String
(Int -> GroupCallDataChannel -> ShowS)
-> (GroupCallDataChannel -> String)
-> ([GroupCallDataChannel] -> ShowS)
-> Show GroupCallDataChannel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GroupCallDataChannel -> ShowS
showsPrec :: Int -> GroupCallDataChannel -> ShowS
$cshow :: GroupCallDataChannel -> String
show :: GroupCallDataChannel -> String
$cshowList :: [GroupCallDataChannel] -> ShowS
showList :: [GroupCallDataChannel] -> ShowS
Show)

instance I.ShortShow GroupCallDataChannel where
  shortShow :: GroupCallDataChannel -> String
shortShow GroupCallDataChannel
GroupCallDataChannelMain
      = String
"GroupCallDataChannelMain"
  shortShow GroupCallDataChannel
GroupCallDataChannelScreenSharing
      = String
"GroupCallDataChannelScreenSharing"

instance AT.FromJSON GroupCallDataChannel where
  parseJSON :: Value -> Parser GroupCallDataChannel
parseJSON (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
"groupCallDataChannelMain"          -> GroupCallDataChannel -> Parser GroupCallDataChannel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure GroupCallDataChannel
GroupCallDataChannelMain
      String
"groupCallDataChannelScreenSharing" -> GroupCallDataChannel -> Parser GroupCallDataChannel
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure GroupCallDataChannel
GroupCallDataChannelScreenSharing
      String
_                                   -> Parser GroupCallDataChannel
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser GroupCallDataChannel
forall a. Monoid a => a
mempty

instance AT.ToJSON GroupCallDataChannel where
  toJSON :: GroupCallDataChannel -> Value
toJSON GroupCallDataChannel
GroupCallDataChannelMain
      = [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
"groupCallDataChannelMain"
        ]
  toJSON GroupCallDataChannel
GroupCallDataChannelScreenSharing
      = [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
"groupCallDataChannelScreenSharing"
        ]