module TD.Query.SetFileGenerationProgress
  (SetFileGenerationProgress(..)
  , defaultSetFileGenerationProgress
  ) where

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

-- | Informs TDLib on a file generation progress. Returns 'TD.Data.Ok.Ok'
data SetFileGenerationProgress
  = SetFileGenerationProgress
    { SetFileGenerationProgress -> Maybe Int
generation_id     :: Maybe Int -- ^ The identifier of the generation process
    , SetFileGenerationProgress -> Maybe Int
expected_size     :: Maybe Int -- ^ Expected size of the generated file, in bytes; 0 if unknown
    , SetFileGenerationProgress -> Maybe Int
local_prefix_size :: Maybe Int -- ^ The number of bytes already generated
    }
  deriving (SetFileGenerationProgress -> SetFileGenerationProgress -> Bool
(SetFileGenerationProgress -> SetFileGenerationProgress -> Bool)
-> (SetFileGenerationProgress -> SetFileGenerationProgress -> Bool)
-> Eq SetFileGenerationProgress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetFileGenerationProgress -> SetFileGenerationProgress -> Bool
== :: SetFileGenerationProgress -> SetFileGenerationProgress -> Bool
$c/= :: SetFileGenerationProgress -> SetFileGenerationProgress -> Bool
/= :: SetFileGenerationProgress -> SetFileGenerationProgress -> Bool
Eq, Int -> SetFileGenerationProgress -> ShowS
[SetFileGenerationProgress] -> ShowS
SetFileGenerationProgress -> String
(Int -> SetFileGenerationProgress -> ShowS)
-> (SetFileGenerationProgress -> String)
-> ([SetFileGenerationProgress] -> ShowS)
-> Show SetFileGenerationProgress
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetFileGenerationProgress -> ShowS
showsPrec :: Int -> SetFileGenerationProgress -> ShowS
$cshow :: SetFileGenerationProgress -> String
show :: SetFileGenerationProgress -> String
$cshowList :: [SetFileGenerationProgress] -> ShowS
showList :: [SetFileGenerationProgress] -> ShowS
Show)

instance I.ShortShow SetFileGenerationProgress where
  shortShow :: SetFileGenerationProgress -> String
shortShow
    SetFileGenerationProgress
      { generation_id :: SetFileGenerationProgress -> Maybe Int
generation_id     = Maybe Int
generation_id_
      , expected_size :: SetFileGenerationProgress -> Maybe Int
expected_size     = Maybe Int
expected_size_
      , local_prefix_size :: SetFileGenerationProgress -> Maybe Int
local_prefix_size = Maybe Int
local_prefix_size_
      }
        = String
"SetFileGenerationProgress"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"generation_id"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
generation_id_
          , String
"expected_size"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expected_size_
          , String
"local_prefix_size" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
local_prefix_size_
          ]

instance AT.ToJSON SetFileGenerationProgress where
  toJSON :: SetFileGenerationProgress -> Value
toJSON
    SetFileGenerationProgress
      { generation_id :: SetFileGenerationProgress -> Maybe Int
generation_id     = Maybe Int
generation_id_
      , expected_size :: SetFileGenerationProgress -> Maybe Int
expected_size     = Maybe Int
expected_size_
      , local_prefix_size :: SetFileGenerationProgress -> Maybe Int
local_prefix_size = Maybe Int
local_prefix_size_
      }
        = [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
"setFileGenerationProgress"
          , Key
"generation_id"     Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64  Maybe Int
generation_id_
          , Key
"expected_size"     Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
expected_size_
          , Key
"local_prefix_size" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
local_prefix_size_
          ]

defaultSetFileGenerationProgress :: SetFileGenerationProgress
defaultSetFileGenerationProgress :: SetFileGenerationProgress
defaultSetFileGenerationProgress =
  SetFileGenerationProgress
    { generation_id :: Maybe Int
generation_id     = Maybe Int
forall a. Maybe a
Nothing
    , expected_size :: Maybe Int
expected_size     = Maybe Int
forall a. Maybe a
Nothing
    , local_prefix_size :: Maybe Int
local_prefix_size = Maybe Int
forall a. Maybe a
Nothing
    }