module TD.Query.DownloadFile
  (DownloadFile(..)
  , defaultDownloadFile
  ) where

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

-- | Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates. Returns 'TD.Data.File.File'
data DownloadFile
  = DownloadFile
    { DownloadFile -> Maybe Int
file_id     :: Maybe Int  -- ^ Identifier of the file to download
    , DownloadFile -> 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
    , DownloadFile -> Maybe Int
offset      :: Maybe Int  -- ^ The starting position from which the file needs to be downloaded
    , DownloadFile -> Maybe Int
limit       :: Maybe Int  -- ^ Number of bytes which need to be downloaded starting from the "offset" position before the download will automatically be canceled; use 0 to download without a limit
    , DownloadFile -> Maybe Bool
synchronous :: Maybe Bool -- ^ Pass true to return response only after the file download has succeeded, has failed, has been canceled, or a new downloadFile request with different offset/limit parameters was sent; pass false to return file state immediately, just after the download has been started
    }
  deriving (DownloadFile -> DownloadFile -> Bool
(DownloadFile -> DownloadFile -> Bool)
-> (DownloadFile -> DownloadFile -> Bool) -> Eq DownloadFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DownloadFile -> DownloadFile -> Bool
== :: DownloadFile -> DownloadFile -> Bool
$c/= :: DownloadFile -> DownloadFile -> Bool
/= :: DownloadFile -> DownloadFile -> Bool
Eq, Int -> DownloadFile -> ShowS
[DownloadFile] -> ShowS
DownloadFile -> String
(Int -> DownloadFile -> ShowS)
-> (DownloadFile -> String)
-> ([DownloadFile] -> ShowS)
-> Show DownloadFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DownloadFile -> ShowS
showsPrec :: Int -> DownloadFile -> ShowS
$cshow :: DownloadFile -> String
show :: DownloadFile -> String
$cshowList :: [DownloadFile] -> ShowS
showList :: [DownloadFile] -> ShowS
Show)

instance I.ShortShow DownloadFile where
  shortShow :: DownloadFile -> String
shortShow
    DownloadFile
      { file_id :: DownloadFile -> Maybe Int
file_id     = Maybe Int
file_id_
      , priority :: DownloadFile -> Maybe Int
priority    = Maybe Int
priority_
      , offset :: DownloadFile -> Maybe Int
offset      = Maybe Int
offset_
      , limit :: DownloadFile -> Maybe Int
limit       = Maybe Int
limit_
      , synchronous :: DownloadFile -> Maybe Bool
synchronous = Maybe Bool
synchronous_
      }
        = String
"DownloadFile"
          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
"priority"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
priority_
          , String
"offset"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
offset_
          , String
"limit"       String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          , String
"synchronous" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
synchronous_
          ]

instance AT.ToJSON DownloadFile where
  toJSON :: DownloadFile -> Value
toJSON
    DownloadFile
      { file_id :: DownloadFile -> Maybe Int
file_id     = Maybe Int
file_id_
      , priority :: DownloadFile -> Maybe Int
priority    = Maybe Int
priority_
      , offset :: DownloadFile -> Maybe Int
offset      = Maybe Int
offset_
      , limit :: DownloadFile -> Maybe Int
limit       = Maybe Int
limit_
      , synchronous :: DownloadFile -> Maybe Bool
synchronous = Maybe Bool
synchronous_
      }
        = [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
"downloadFile"
          , 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
"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_
          , Key
"offset"      Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
offset_
          , Key
"limit"       Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
limit_
          , Key
"synchronous" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
synchronous_
          ]

defaultDownloadFile :: DownloadFile
defaultDownloadFile :: DownloadFile
defaultDownloadFile =
  DownloadFile
    { file_id :: Maybe Int
file_id     = Maybe Int
forall a. Maybe a
Nothing
    , priority :: Maybe Int
priority    = Maybe Int
forall a. Maybe a
Nothing
    , offset :: Maybe Int
offset      = Maybe Int
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit       = Maybe Int
forall a. Maybe a
Nothing
    , synchronous :: Maybe Bool
synchronous = Maybe Bool
forall a. Maybe a
Nothing
    }