module TD.Data.FileDownloadedPrefixSize
  (FileDownloadedPrefixSize(..)) where

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

data FileDownloadedPrefixSize
  = FileDownloadedPrefixSize -- ^ Contains size of downloaded prefix of a file
    { FileDownloadedPrefixSize -> Maybe Int
size :: Maybe Int -- ^ The prefix size, in bytes
    }
  deriving (FileDownloadedPrefixSize -> FileDownloadedPrefixSize -> Bool
(FileDownloadedPrefixSize -> FileDownloadedPrefixSize -> Bool)
-> (FileDownloadedPrefixSize -> FileDownloadedPrefixSize -> Bool)
-> Eq FileDownloadedPrefixSize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FileDownloadedPrefixSize -> FileDownloadedPrefixSize -> Bool
== :: FileDownloadedPrefixSize -> FileDownloadedPrefixSize -> Bool
$c/= :: FileDownloadedPrefixSize -> FileDownloadedPrefixSize -> Bool
/= :: FileDownloadedPrefixSize -> FileDownloadedPrefixSize -> Bool
Eq, Int -> FileDownloadedPrefixSize -> ShowS
[FileDownloadedPrefixSize] -> ShowS
FileDownloadedPrefixSize -> String
(Int -> FileDownloadedPrefixSize -> ShowS)
-> (FileDownloadedPrefixSize -> String)
-> ([FileDownloadedPrefixSize] -> ShowS)
-> Show FileDownloadedPrefixSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FileDownloadedPrefixSize -> ShowS
showsPrec :: Int -> FileDownloadedPrefixSize -> ShowS
$cshow :: FileDownloadedPrefixSize -> String
show :: FileDownloadedPrefixSize -> String
$cshowList :: [FileDownloadedPrefixSize] -> ShowS
showList :: [FileDownloadedPrefixSize] -> ShowS
Show)

instance I.ShortShow FileDownloadedPrefixSize where
  shortShow :: FileDownloadedPrefixSize -> String
shortShow FileDownloadedPrefixSize
    { size :: FileDownloadedPrefixSize -> Maybe Int
size = Maybe Int
size_
    }
      = String
"FileDownloadedPrefixSize"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"size" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
size_
        ]

instance AT.FromJSON FileDownloadedPrefixSize where
  parseJSON :: Value -> Parser FileDownloadedPrefixSize
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
"fileDownloadedPrefixSize" -> Value -> Parser FileDownloadedPrefixSize
parseFileDownloadedPrefixSize Value
v
      String
_                          -> Parser FileDownloadedPrefixSize
forall a. Monoid a => a
mempty
    
    where
      parseFileDownloadedPrefixSize :: A.Value -> AT.Parser FileDownloadedPrefixSize
      parseFileDownloadedPrefixSize :: Value -> Parser FileDownloadedPrefixSize
parseFileDownloadedPrefixSize = String
-> (Object -> Parser FileDownloadedPrefixSize)
-> Value
-> Parser FileDownloadedPrefixSize
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"FileDownloadedPrefixSize" ((Object -> Parser FileDownloadedPrefixSize)
 -> Value -> Parser FileDownloadedPrefixSize)
-> (Object -> Parser FileDownloadedPrefixSize)
-> Value
-> Parser FileDownloadedPrefixSize
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
size_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"size"
        FileDownloadedPrefixSize -> Parser FileDownloadedPrefixSize
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FileDownloadedPrefixSize -> Parser FileDownloadedPrefixSize)
-> FileDownloadedPrefixSize -> Parser FileDownloadedPrefixSize
forall a b. (a -> b) -> a -> b
$ FileDownloadedPrefixSize
          { size :: Maybe Int
size = Maybe Int
size_
          }
  parseJSON Value
_ = Parser FileDownloadedPrefixSize
forall a. Monoid a => a
mempty