module TD.Query.AddFileToDownloads
  (AddFileToDownloads(..)
  , defaultAddFileToDownloads
  ) where

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

-- | Adds a file from a message to the list of file downloads. Download progress and completion of the download will be notified through updateFile updates. If message database is used, the list of file downloads is persistent across application restarts. The downloading is independent of download using downloadFile, i.e. it continues if downloadFile is canceled or is used to download a part of the file. Returns 'TD.Data.File.File'
data AddFileToDownloads
  = AddFileToDownloads
    { AddFileToDownloads -> Maybe Int
file_id    :: Maybe Int -- ^ Identifier of the file to download
    , AddFileToDownloads -> Maybe Int
chat_id    :: Maybe Int -- ^ Chat identifier of the message with the file
    , AddFileToDownloads -> Maybe Int
message_id :: Maybe Int -- ^ Message identifier
    , AddFileToDownloads -> Maybe Int
priority   :: Maybe Int -- ^ Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile/addFileToDownloads was called will be downloaded first
    }
  deriving (AddFileToDownloads -> AddFileToDownloads -> Bool
(AddFileToDownloads -> AddFileToDownloads -> Bool)
-> (AddFileToDownloads -> AddFileToDownloads -> Bool)
-> Eq AddFileToDownloads
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AddFileToDownloads -> AddFileToDownloads -> Bool
== :: AddFileToDownloads -> AddFileToDownloads -> Bool
$c/= :: AddFileToDownloads -> AddFileToDownloads -> Bool
/= :: AddFileToDownloads -> AddFileToDownloads -> Bool
Eq, Int -> AddFileToDownloads -> ShowS
[AddFileToDownloads] -> ShowS
AddFileToDownloads -> String
(Int -> AddFileToDownloads -> ShowS)
-> (AddFileToDownloads -> String)
-> ([AddFileToDownloads] -> ShowS)
-> Show AddFileToDownloads
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddFileToDownloads -> ShowS
showsPrec :: Int -> AddFileToDownloads -> ShowS
$cshow :: AddFileToDownloads -> String
show :: AddFileToDownloads -> String
$cshowList :: [AddFileToDownloads] -> ShowS
showList :: [AddFileToDownloads] -> ShowS
Show)

instance I.ShortShow AddFileToDownloads where
  shortShow :: AddFileToDownloads -> String
shortShow
    AddFileToDownloads
      { file_id :: AddFileToDownloads -> Maybe Int
file_id    = Maybe Int
file_id_
      , chat_id :: AddFileToDownloads -> Maybe Int
chat_id    = Maybe Int
chat_id_
      , message_id :: AddFileToDownloads -> Maybe Int
message_id = Maybe Int
message_id_
      , priority :: AddFileToDownloads -> Maybe Int
priority   = Maybe Int
priority_
      }
        = String
"AddFileToDownloads"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"file_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
file_id_
          , String
"chat_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
          , String
"priority"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
priority_
          ]

instance AT.ToJSON AddFileToDownloads where
  toJSON :: AddFileToDownloads -> Value
toJSON
    AddFileToDownloads
      { file_id :: AddFileToDownloads -> Maybe Int
file_id    = Maybe Int
file_id_
      , chat_id :: AddFileToDownloads -> Maybe Int
chat_id    = Maybe Int
chat_id_
      , message_id :: AddFileToDownloads -> Maybe Int
message_id = Maybe Int
message_id_
      , priority :: AddFileToDownloads -> Maybe Int
priority   = Maybe Int
priority_
      }
        = [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
"addFileToDownloads"
          , Key
"file_id"    Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
file_id_
          , Key
"chat_id"    Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
chat_id_
          , Key
"message_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
message_id_
          , Key
"priority"   Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
priority_
          ]

defaultAddFileToDownloads :: AddFileToDownloads
defaultAddFileToDownloads :: AddFileToDownloads
defaultAddFileToDownloads =
  AddFileToDownloads
    { file_id :: Maybe Int
file_id    = Maybe Int
forall a. Maybe a
Nothing
    , chat_id :: Maybe Int
chat_id    = Maybe Int
forall a. Maybe a
Nothing
    , message_id :: Maybe Int
message_id = Maybe Int
forall a. Maybe a
Nothing
    , priority :: Maybe Int
priority   = Maybe Int
forall a. Maybe a
Nothing
    }