module TD.Data.Video
  (Video(..)) 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
import qualified TD.Data.Minithumbnail as Minithumbnail
import qualified TD.Data.Thumbnail as Thumbnail
import qualified TD.Data.File as File

data Video
  = Video -- ^ Describes a video file
    { Video -> Maybe Int
duration           :: Maybe Int                         -- ^ Duration of the video, in seconds; as defined by the sender
    , Video -> Maybe Int
width              :: Maybe Int                         -- ^ Video width; as defined by the sender
    , Video -> Maybe Int
height             :: Maybe Int                         -- ^ Video height; as defined by the sender
    , Video -> Maybe Text
file_name          :: Maybe T.Text                      -- ^ Original name of the file; as defined by the sender
    , Video -> Maybe Text
mime_type          :: Maybe T.Text                      -- ^ MIME type of the file; as defined by the sender
    , Video -> Maybe Bool
has_stickers       :: Maybe Bool                        -- ^ True, if stickers were added to the video. The list of corresponding sticker sets can be received using getAttachedStickerSets
    , Video -> Maybe Bool
supports_streaming :: Maybe Bool                        -- ^ True, if the video is expected to be streamed
    , Video -> Maybe Minithumbnail
minithumbnail      :: Maybe Minithumbnail.Minithumbnail -- ^ Video minithumbnail; may be null
    , Video -> Maybe Thumbnail
thumbnail          :: Maybe Thumbnail.Thumbnail         -- ^ Video thumbnail in JPEG or MPEG4 format; as defined by the sender; may be null
    , Video -> Maybe File
video              :: Maybe File.File                   -- ^ File containing the video
    }
  deriving (Video -> Video -> Bool
(Video -> Video -> Bool) -> (Video -> Video -> Bool) -> Eq Video
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Video -> Video -> Bool
== :: Video -> Video -> Bool
$c/= :: Video -> Video -> Bool
/= :: Video -> Video -> Bool
Eq, Int -> Video -> ShowS
[Video] -> ShowS
Video -> String
(Int -> Video -> ShowS)
-> (Video -> String) -> ([Video] -> ShowS) -> Show Video
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Video -> ShowS
showsPrec :: Int -> Video -> ShowS
$cshow :: Video -> String
show :: Video -> String
$cshowList :: [Video] -> ShowS
showList :: [Video] -> ShowS
Show)

instance I.ShortShow Video where
  shortShow :: Video -> String
shortShow Video
    { duration :: Video -> Maybe Int
duration           = Maybe Int
duration_
    , width :: Video -> Maybe Int
width              = Maybe Int
width_
    , height :: Video -> Maybe Int
height             = Maybe Int
height_
    , file_name :: Video -> Maybe Text
file_name          = Maybe Text
file_name_
    , mime_type :: Video -> Maybe Text
mime_type          = Maybe Text
mime_type_
    , has_stickers :: Video -> Maybe Bool
has_stickers       = Maybe Bool
has_stickers_
    , supports_streaming :: Video -> Maybe Bool
supports_streaming = Maybe Bool
supports_streaming_
    , minithumbnail :: Video -> Maybe Minithumbnail
minithumbnail      = Maybe Minithumbnail
minithumbnail_
    , thumbnail :: Video -> Maybe Thumbnail
thumbnail          = Maybe Thumbnail
thumbnail_
    , video :: Video -> Maybe File
video              = Maybe File
video_
    }
      = String
"Video"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"duration"           String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
duration_
        , String
"width"              String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
width_
        , String
"height"             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
height_
        , String
"file_name"          String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
file_name_
        , String
"mime_type"          String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
mime_type_
        , String
"has_stickers"       String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_stickers_
        , String
"supports_streaming" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
supports_streaming_
        , String
"minithumbnail"      String -> Maybe Minithumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Minithumbnail
minithumbnail_
        , String
"thumbnail"          String -> Maybe Thumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Thumbnail
thumbnail_
        , String
"video"              String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
video_
        ]

instance AT.FromJSON Video where
  parseJSON :: Value -> Parser Video
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
"video" -> Value -> Parser Video
parseVideo Value
v
      String
_       -> Parser Video
forall a. Monoid a => a
mempty
    
    where
      parseVideo :: A.Value -> AT.Parser Video
      parseVideo :: Value -> Parser Video
parseVideo = String -> (Object -> Parser Video) -> Value -> Parser Video
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Video" ((Object -> Parser Video) -> Value -> Parser Video)
-> (Object -> Parser Video) -> Value -> Parser Video
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
duration_           <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"duration"
        Maybe Int
width_              <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"width"
        Maybe Int
height_             <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"height"
        Maybe Text
file_name_          <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"file_name"
        Maybe Text
mime_type_          <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"mime_type"
        Maybe Bool
has_stickers_       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"has_stickers"
        Maybe Bool
supports_streaming_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"supports_streaming"
        Maybe Minithumbnail
minithumbnail_      <- Object
o Object -> Key -> Parser (Maybe Minithumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"minithumbnail"
        Maybe Thumbnail
thumbnail_          <- Object
o Object -> Key -> Parser (Maybe Thumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"thumbnail"
        Maybe File
video_              <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"video"
        Video -> Parser Video
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Video -> Parser Video) -> Video -> Parser Video
forall a b. (a -> b) -> a -> b
$ Video
          { duration :: Maybe Int
duration           = Maybe Int
duration_
          , width :: Maybe Int
width              = Maybe Int
width_
          , height :: Maybe Int
height             = Maybe Int
height_
          , file_name :: Maybe Text
file_name          = Maybe Text
file_name_
          , mime_type :: Maybe Text
mime_type          = Maybe Text
mime_type_
          , has_stickers :: Maybe Bool
has_stickers       = Maybe Bool
has_stickers_
          , supports_streaming :: Maybe Bool
supports_streaming = Maybe Bool
supports_streaming_
          , minithumbnail :: Maybe Minithumbnail
minithumbnail      = Maybe Minithumbnail
minithumbnail_
          , thumbnail :: Maybe Thumbnail
thumbnail          = Maybe Thumbnail
thumbnail_
          , video :: Maybe File
video              = Maybe File
video_
          }
  parseJSON Value
_ = Parser Video
forall a. Monoid a => a
mempty