module TD.Data.VideoChatStream
  (VideoChatStream(..)) where

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

data VideoChatStream
  = VideoChatStream -- ^ Describes an available stream in a video chat
    { VideoChatStream -> Maybe Int
channel_id  :: Maybe Int -- ^ Identifier of an audio/video channel
    , VideoChatStream -> Maybe Int
scale       :: Maybe Int -- ^ Scale of segment durations in the stream. The duration is 1000/(2**scale) milliseconds
    , VideoChatStream -> Maybe Int
time_offset :: Maybe Int -- ^ Point in time when the stream currently ends; Unix timestamp in milliseconds
    }
  deriving (VideoChatStream -> VideoChatStream -> Bool
(VideoChatStream -> VideoChatStream -> Bool)
-> (VideoChatStream -> VideoChatStream -> Bool)
-> Eq VideoChatStream
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VideoChatStream -> VideoChatStream -> Bool
== :: VideoChatStream -> VideoChatStream -> Bool
$c/= :: VideoChatStream -> VideoChatStream -> Bool
/= :: VideoChatStream -> VideoChatStream -> Bool
Eq, Int -> VideoChatStream -> ShowS
[VideoChatStream] -> ShowS
VideoChatStream -> String
(Int -> VideoChatStream -> ShowS)
-> (VideoChatStream -> String)
-> ([VideoChatStream] -> ShowS)
-> Show VideoChatStream
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VideoChatStream -> ShowS
showsPrec :: Int -> VideoChatStream -> ShowS
$cshow :: VideoChatStream -> String
show :: VideoChatStream -> String
$cshowList :: [VideoChatStream] -> ShowS
showList :: [VideoChatStream] -> ShowS
Show)

instance I.ShortShow VideoChatStream where
  shortShow :: VideoChatStream -> String
shortShow VideoChatStream
    { channel_id :: VideoChatStream -> Maybe Int
channel_id  = Maybe Int
channel_id_
    , scale :: VideoChatStream -> Maybe Int
scale       = Maybe Int
scale_
    , time_offset :: VideoChatStream -> Maybe Int
time_offset = Maybe Int
time_offset_
    }
      = String
"VideoChatStream"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"channel_id"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
channel_id_
        , String
"scale"       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
scale_
        , String
"time_offset" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
time_offset_
        ]

instance AT.FromJSON VideoChatStream where
  parseJSON :: Value -> Parser VideoChatStream
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
"videoChatStream" -> Value -> Parser VideoChatStream
parseVideoChatStream Value
v
      String
_                 -> Parser VideoChatStream
forall a. Monoid a => a
mempty
    
    where
      parseVideoChatStream :: A.Value -> AT.Parser VideoChatStream
      parseVideoChatStream :: Value -> Parser VideoChatStream
parseVideoChatStream = String
-> (Object -> Parser VideoChatStream)
-> Value
-> Parser VideoChatStream
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"VideoChatStream" ((Object -> Parser VideoChatStream)
 -> Value -> Parser VideoChatStream)
-> (Object -> Parser VideoChatStream)
-> Value
-> Parser VideoChatStream
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
channel_id_  <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"channel_id"
        Maybe Int
scale_       <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"scale"
        Maybe Int
time_offset_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"time_offset"
        VideoChatStream -> Parser VideoChatStream
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (VideoChatStream -> Parser VideoChatStream)
-> VideoChatStream -> Parser VideoChatStream
forall a b. (a -> b) -> a -> b
$ VideoChatStream
          { channel_id :: Maybe Int
channel_id  = Maybe Int
channel_id_
          , scale :: Maybe Int
scale       = Maybe Int
scale_
          , time_offset :: Maybe Int
time_offset = Maybe Int
time_offset_
          }
  parseJSON Value
_ = Parser VideoChatStream
forall a. Monoid a => a
mempty