module TD.Data.AlternativeVideo
  (AlternativeVideo(..)) 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.File as File

data AlternativeVideo
  = AlternativeVideo -- ^ Describes an alternative reencoded quality of a video file
    { AlternativeVideo -> Maybe Int
width    :: Maybe Int       -- ^ Video width
    , AlternativeVideo -> Maybe Int
height   :: Maybe Int       -- ^ Video height
    , AlternativeVideo -> Maybe Text
codec    :: Maybe T.Text    -- ^ Codec used for video file encoding, for example, "h264", "h265", or "av1"
    , AlternativeVideo -> Maybe File
hls_file :: Maybe File.File -- ^ HLS file describing the video
    , AlternativeVideo -> Maybe File
video    :: Maybe File.File -- ^ File containing the video
    }
  deriving (AlternativeVideo -> AlternativeVideo -> Bool
(AlternativeVideo -> AlternativeVideo -> Bool)
-> (AlternativeVideo -> AlternativeVideo -> Bool)
-> Eq AlternativeVideo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AlternativeVideo -> AlternativeVideo -> Bool
== :: AlternativeVideo -> AlternativeVideo -> Bool
$c/= :: AlternativeVideo -> AlternativeVideo -> Bool
/= :: AlternativeVideo -> AlternativeVideo -> Bool
Eq, Int -> AlternativeVideo -> ShowS
[AlternativeVideo] -> ShowS
AlternativeVideo -> String
(Int -> AlternativeVideo -> ShowS)
-> (AlternativeVideo -> String)
-> ([AlternativeVideo] -> ShowS)
-> Show AlternativeVideo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AlternativeVideo -> ShowS
showsPrec :: Int -> AlternativeVideo -> ShowS
$cshow :: AlternativeVideo -> String
show :: AlternativeVideo -> String
$cshowList :: [AlternativeVideo] -> ShowS
showList :: [AlternativeVideo] -> ShowS
Show)

instance I.ShortShow AlternativeVideo where
  shortShow :: AlternativeVideo -> String
shortShow AlternativeVideo
    { width :: AlternativeVideo -> Maybe Int
width    = Maybe Int
width_
    , height :: AlternativeVideo -> Maybe Int
height   = Maybe Int
height_
    , codec :: AlternativeVideo -> Maybe Text
codec    = Maybe Text
codec_
    , hls_file :: AlternativeVideo -> Maybe File
hls_file = Maybe File
hls_file_
    , video :: AlternativeVideo -> Maybe File
video    = Maybe File
video_
    }
      = String
"AlternativeVideo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ 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
"codec"    String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
codec_
        , String
"hls_file" String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
hls_file_
        , String
"video"    String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
video_
        ]

instance AT.FromJSON AlternativeVideo where
  parseJSON :: Value -> Parser AlternativeVideo
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
"alternativeVideo" -> Value -> Parser AlternativeVideo
parseAlternativeVideo Value
v
      String
_                  -> Parser AlternativeVideo
forall a. Monoid a => a
mempty
    
    where
      parseAlternativeVideo :: A.Value -> AT.Parser AlternativeVideo
      parseAlternativeVideo :: Value -> Parser AlternativeVideo
parseAlternativeVideo = String
-> (Object -> Parser AlternativeVideo)
-> Value
-> Parser AlternativeVideo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AlternativeVideo" ((Object -> Parser AlternativeVideo)
 -> Value -> Parser AlternativeVideo)
-> (Object -> Parser AlternativeVideo)
-> Value
-> Parser AlternativeVideo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        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
codec_    <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"codec"
        Maybe File
hls_file_ <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"hls_file"
        Maybe File
video_    <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"video"
        AlternativeVideo -> Parser AlternativeVideo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AlternativeVideo -> Parser AlternativeVideo)
-> AlternativeVideo -> Parser AlternativeVideo
forall a b. (a -> b) -> a -> b
$ AlternativeVideo
          { width :: Maybe Int
width    = Maybe Int
width_
          , height :: Maybe Int
height   = Maybe Int
height_
          , codec :: Maybe Text
codec    = Maybe Text
codec_
          , hls_file :: Maybe File
hls_file = Maybe File
hls_file_
          , video :: Maybe File
video    = Maybe File
video_
          }
  parseJSON Value
_ = Parser AlternativeVideo
forall a. Monoid a => a
mempty