module TD.Data.StoryVideo
  (StoryVideo(..)) where

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

data StoryVideo
  = StoryVideo -- ^ Describes a video file sent in a story
    { StoryVideo -> Maybe Double
duration              :: Maybe Double                      -- ^ Duration of the video, in seconds
    , StoryVideo -> Maybe Int
width                 :: Maybe Int                         -- ^ Video width
    , StoryVideo -> Maybe Int
height                :: Maybe Int                         -- ^ Video height
    , StoryVideo -> 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
    , StoryVideo -> Maybe Bool
is_animation          :: Maybe Bool                        -- ^ True, if the video has no sound
    , StoryVideo -> Maybe Minithumbnail
minithumbnail         :: Maybe Minithumbnail.Minithumbnail -- ^ Video minithumbnail; may be null
    , StoryVideo -> Maybe Thumbnail
thumbnail             :: Maybe Thumbnail.Thumbnail         -- ^ Video thumbnail in JPEG or MPEG4 format; may be null
    , StoryVideo -> Maybe Int
preload_prefix_size   :: Maybe Int                         -- ^ Size of file prefix, which is expected to be preloaded, in bytes
    , StoryVideo -> Maybe Double
cover_frame_timestamp :: Maybe Double                      -- ^ Timestamp of the frame used as video thumbnail
    , StoryVideo -> Maybe File
video                 :: Maybe File.File                   -- ^ File containing the video
    }
  deriving (StoryVideo -> StoryVideo -> Bool
(StoryVideo -> StoryVideo -> Bool)
-> (StoryVideo -> StoryVideo -> Bool) -> Eq StoryVideo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StoryVideo -> StoryVideo -> Bool
== :: StoryVideo -> StoryVideo -> Bool
$c/= :: StoryVideo -> StoryVideo -> Bool
/= :: StoryVideo -> StoryVideo -> Bool
Eq, Int -> StoryVideo -> ShowS
[StoryVideo] -> ShowS
StoryVideo -> String
(Int -> StoryVideo -> ShowS)
-> (StoryVideo -> String)
-> ([StoryVideo] -> ShowS)
-> Show StoryVideo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StoryVideo -> ShowS
showsPrec :: Int -> StoryVideo -> ShowS
$cshow :: StoryVideo -> String
show :: StoryVideo -> String
$cshowList :: [StoryVideo] -> ShowS
showList :: [StoryVideo] -> ShowS
Show)

instance I.ShortShow StoryVideo where
  shortShow :: StoryVideo -> String
shortShow StoryVideo
    { duration :: StoryVideo -> Maybe Double
duration              = Maybe Double
duration_
    , width :: StoryVideo -> Maybe Int
width                 = Maybe Int
width_
    , height :: StoryVideo -> Maybe Int
height                = Maybe Int
height_
    , has_stickers :: StoryVideo -> Maybe Bool
has_stickers          = Maybe Bool
has_stickers_
    , is_animation :: StoryVideo -> Maybe Bool
is_animation          = Maybe Bool
is_animation_
    , minithumbnail :: StoryVideo -> Maybe Minithumbnail
minithumbnail         = Maybe Minithumbnail
minithumbnail_
    , thumbnail :: StoryVideo -> Maybe Thumbnail
thumbnail             = Maybe Thumbnail
thumbnail_
    , preload_prefix_size :: StoryVideo -> Maybe Int
preload_prefix_size   = Maybe Int
preload_prefix_size_
    , cover_frame_timestamp :: StoryVideo -> Maybe Double
cover_frame_timestamp = Maybe Double
cover_frame_timestamp_
    , video :: StoryVideo -> Maybe File
video                 = Maybe File
video_
    }
      = String
"StoryVideo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"duration"              String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
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
"has_stickers"          String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_stickers_
        , String
"is_animation"          String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_animation_
        , 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
"preload_prefix_size"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
preload_prefix_size_
        , String
"cover_frame_timestamp" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
cover_frame_timestamp_
        , String
"video"                 String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
video_
        ]

instance AT.FromJSON StoryVideo where
  parseJSON :: Value -> Parser StoryVideo
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
"storyVideo" -> Value -> Parser StoryVideo
parseStoryVideo Value
v
      String
_            -> Parser StoryVideo
forall a. Monoid a => a
mempty
    
    where
      parseStoryVideo :: A.Value -> AT.Parser StoryVideo
      parseStoryVideo :: Value -> Parser StoryVideo
parseStoryVideo = String
-> (Object -> Parser StoryVideo) -> Value -> Parser StoryVideo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryVideo" ((Object -> Parser StoryVideo) -> Value -> Parser StoryVideo)
-> (Object -> Parser StoryVideo) -> Value -> Parser StoryVideo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Double
duration_              <- Object
o Object -> Key -> Parser (Maybe Double)
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 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
is_animation_          <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_animation"
        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 Int
preload_prefix_size_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"preload_prefix_size"
        Maybe Double
cover_frame_timestamp_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"cover_frame_timestamp"
        Maybe File
video_                 <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"video"
        StoryVideo -> Parser StoryVideo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryVideo -> Parser StoryVideo)
-> StoryVideo -> Parser StoryVideo
forall a b. (a -> b) -> a -> b
$ StoryVideo
          { duration :: Maybe Double
duration              = Maybe Double
duration_
          , width :: Maybe Int
width                 = Maybe Int
width_
          , height :: Maybe Int
height                = Maybe Int
height_
          , has_stickers :: Maybe Bool
has_stickers          = Maybe Bool
has_stickers_
          , is_animation :: Maybe Bool
is_animation          = Maybe Bool
is_animation_
          , minithumbnail :: Maybe Minithumbnail
minithumbnail         = Maybe Minithumbnail
minithumbnail_
          , thumbnail :: Maybe Thumbnail
thumbnail             = Maybe Thumbnail
thumbnail_
          , preload_prefix_size :: Maybe Int
preload_prefix_size   = Maybe Int
preload_prefix_size_
          , cover_frame_timestamp :: Maybe Double
cover_frame_timestamp = Maybe Double
cover_frame_timestamp_
          , video :: Maybe File
video                 = Maybe File
video_
          }
  parseJSON Value
_ = Parser StoryVideo
forall a. Monoid a => a
mempty