module TD.Data.InputVideo
  ( InputVideo(..)    
  , defaultInputVideo 
  ) 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.InputFile as InputFile
import qualified TD.Data.InputThumbnail as InputThumbnail

data InputVideo
  = InputVideo -- ^ A video to be sent
    { InputVideo -> Maybe InputFile
video                  :: Maybe InputFile.InputFile           -- ^ Video file to be sent. The video is expected to be re-encoded to MPEG4 format with H.264 codec by the sender
    , InputVideo -> Maybe InputThumbnail
thumbnail              :: Maybe InputThumbnail.InputThumbnail -- ^ Video thumbnail; pass null to skip thumbnail uploading
    , InputVideo -> Maybe InputFile
cover                  :: Maybe InputFile.InputFile           -- ^ Cover of the video; pass null to skip cover uploading; not supported in secret chats and for self-destructing messages
    , InputVideo -> Maybe Int
start_timestamp        :: Maybe Int                           -- ^ Timestamp from which the video playing must start, in seconds
    , InputVideo -> Maybe [Int]
added_sticker_file_ids :: Maybe [Int]                         -- ^ File identifiers of the stickers added to the video, if applicable
    , InputVideo -> Maybe Int
duration               :: Maybe Int                           -- ^ Duration of the video, in seconds
    , InputVideo -> Maybe Int
width                  :: Maybe Int                           -- ^ Video width
    , InputVideo -> Maybe Int
height                 :: Maybe Int                           -- ^ Video height
    , InputVideo -> Maybe Bool
supports_streaming     :: Maybe Bool                          -- ^ True, if the video is expected to be streamed
    }
  deriving (InputVideo -> InputVideo -> Bool
(InputVideo -> InputVideo -> Bool)
-> (InputVideo -> InputVideo -> Bool) -> Eq InputVideo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputVideo -> InputVideo -> Bool
== :: InputVideo -> InputVideo -> Bool
$c/= :: InputVideo -> InputVideo -> Bool
/= :: InputVideo -> InputVideo -> Bool
Eq, Int -> InputVideo -> ShowS
[InputVideo] -> ShowS
InputVideo -> String
(Int -> InputVideo -> ShowS)
-> (InputVideo -> String)
-> ([InputVideo] -> ShowS)
-> Show InputVideo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputVideo -> ShowS
showsPrec :: Int -> InputVideo -> ShowS
$cshow :: InputVideo -> String
show :: InputVideo -> String
$cshowList :: [InputVideo] -> ShowS
showList :: [InputVideo] -> ShowS
Show)

instance I.ShortShow InputVideo where
  shortShow :: InputVideo -> String
shortShow InputVideo
    { video :: InputVideo -> Maybe InputFile
video                  = Maybe InputFile
video_
    , thumbnail :: InputVideo -> Maybe InputThumbnail
thumbnail              = Maybe InputThumbnail
thumbnail_
    , cover :: InputVideo -> Maybe InputFile
cover                  = Maybe InputFile
cover_
    , start_timestamp :: InputVideo -> Maybe Int
start_timestamp        = Maybe Int
start_timestamp_
    , added_sticker_file_ids :: InputVideo -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
    , duration :: InputVideo -> Maybe Int
duration               = Maybe Int
duration_
    , width :: InputVideo -> Maybe Int
width                  = Maybe Int
width_
    , height :: InputVideo -> Maybe Int
height                 = Maybe Int
height_
    , supports_streaming :: InputVideo -> Maybe Bool
supports_streaming     = Maybe Bool
supports_streaming_
    }
      = String
"InputVideo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"video"                  String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
video_
        , String
"thumbnail"              String -> Maybe InputThumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputThumbnail
thumbnail_
        , String
"cover"                  String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
cover_
        , String
"start_timestamp"        String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
start_timestamp_
        , String
"added_sticker_file_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
added_sticker_file_ids_
        , 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
"supports_streaming"     String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
supports_streaming_
        ]

instance AT.FromJSON InputVideo where
  parseJSON :: Value -> Parser InputVideo
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
"inputVideo" -> Value -> Parser InputVideo
parseInputVideo Value
v
      String
_            -> Parser InputVideo
forall a. Monoid a => a
mempty
    
    where
      parseInputVideo :: A.Value -> AT.Parser InputVideo
      parseInputVideo :: Value -> Parser InputVideo
parseInputVideo = String
-> (Object -> Parser InputVideo) -> Value -> Parser InputVideo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputVideo" ((Object -> Parser InputVideo) -> Value -> Parser InputVideo)
-> (Object -> Parser InputVideo) -> Value -> Parser InputVideo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe InputFile
video_                  <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"video"
        Maybe InputThumbnail
thumbnail_              <- Object
o Object -> Key -> Parser (Maybe InputThumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"thumbnail"
        Maybe InputFile
cover_                  <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"cover"
        Maybe Int
start_timestamp_        <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"start_timestamp"
        Maybe [Int]
added_sticker_file_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"added_sticker_file_ids"
        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 Bool
supports_streaming_     <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"supports_streaming"
        InputVideo -> Parser InputVideo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputVideo -> Parser InputVideo)
-> InputVideo -> Parser InputVideo
forall a b. (a -> b) -> a -> b
$ InputVideo
          { video :: Maybe InputFile
video                  = Maybe InputFile
video_
          , thumbnail :: Maybe InputThumbnail
thumbnail              = Maybe InputThumbnail
thumbnail_
          , cover :: Maybe InputFile
cover                  = Maybe InputFile
cover_
          , start_timestamp :: Maybe Int
start_timestamp        = Maybe Int
start_timestamp_
          , added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
          , duration :: Maybe Int
duration               = Maybe Int
duration_
          , width :: Maybe Int
width                  = Maybe Int
width_
          , height :: Maybe Int
height                 = Maybe Int
height_
          , supports_streaming :: Maybe Bool
supports_streaming     = Maybe Bool
supports_streaming_
          }
  parseJSON Value
_ = Parser InputVideo
forall a. Monoid a => a
mempty

instance AT.ToJSON InputVideo where
  toJSON :: InputVideo -> Value
toJSON InputVideo
    { video :: InputVideo -> Maybe InputFile
video                  = Maybe InputFile
video_
    , thumbnail :: InputVideo -> Maybe InputThumbnail
thumbnail              = Maybe InputThumbnail
thumbnail_
    , cover :: InputVideo -> Maybe InputFile
cover                  = Maybe InputFile
cover_
    , start_timestamp :: InputVideo -> Maybe Int
start_timestamp        = Maybe Int
start_timestamp_
    , added_sticker_file_ids :: InputVideo -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
    , duration :: InputVideo -> Maybe Int
duration               = Maybe Int
duration_
    , width :: InputVideo -> Maybe Int
width                  = Maybe Int
width_
    , height :: InputVideo -> Maybe Int
height                 = Maybe Int
height_
    , supports_streaming :: InputVideo -> Maybe Bool
supports_streaming     = Maybe Bool
supports_streaming_
    }
      = [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
"inputVideo"
        , Key
"video"                  Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
video_
        , Key
"thumbnail"              Key -> Maybe InputThumbnail -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputThumbnail
thumbnail_
        , Key
"cover"                  Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
cover_
        , Key
"start_timestamp"        Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
start_timestamp_
        , Key
"added_sticker_file_ids" Key -> Maybe [Int] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Int]
added_sticker_file_ids_
        , Key
"duration"               Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
duration_
        , Key
"width"                  Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
width_
        , Key
"height"                 Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
height_
        , Key
"supports_streaming"     Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
supports_streaming_
        ]

defaultInputVideo :: InputVideo
defaultInputVideo :: InputVideo
defaultInputVideo =
  InputVideo
    { video :: Maybe InputFile
video                  = Maybe InputFile
forall a. Maybe a
Nothing
    , thumbnail :: Maybe InputThumbnail
thumbnail              = Maybe InputThumbnail
forall a. Maybe a
Nothing
    , cover :: Maybe InputFile
cover                  = Maybe InputFile
forall a. Maybe a
Nothing
    , start_timestamp :: Maybe Int
start_timestamp        = Maybe Int
forall a. Maybe a
Nothing
    , added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
forall a. Maybe a
Nothing
    , duration :: Maybe Int
duration               = Maybe Int
forall a. Maybe a
Nothing
    , width :: Maybe Int
width                  = Maybe Int
forall a. Maybe a
Nothing
    , height :: Maybe Int
height                 = Maybe Int
forall a. Maybe a
Nothing
    , supports_streaming :: Maybe Bool
supports_streaming     = Maybe Bool
forall a. Maybe a
Nothing
    }