module TD.Query.GetRemoteFile
  (GetRemoteFile(..)
  , defaultGetRemoteFile
  ) 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.FileType as FileType

-- | Returns information about a file by its remote identifier; this is an offline request. Can be used to register a URL as a file for further uploading, or sending as a message. Even the request succeeds, the file can be used only if it is still accessible to the user. For example, if the file is from a message, then the message must be not deleted and accessible to the user. If the file database is disabled, then the corresponding object with the file must be preloaded by the application. Returns 'TD.Data.File.File'
data GetRemoteFile
  = GetRemoteFile
    { GetRemoteFile -> Maybe Text
remote_file_id :: Maybe T.Text            -- ^ Remote identifier of the file to get
    , GetRemoteFile -> Maybe FileType
file_type      :: Maybe FileType.FileType -- ^ File type; pass null if unknown
    }
  deriving (GetRemoteFile -> GetRemoteFile -> Bool
(GetRemoteFile -> GetRemoteFile -> Bool)
-> (GetRemoteFile -> GetRemoteFile -> Bool) -> Eq GetRemoteFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetRemoteFile -> GetRemoteFile -> Bool
== :: GetRemoteFile -> GetRemoteFile -> Bool
$c/= :: GetRemoteFile -> GetRemoteFile -> Bool
/= :: GetRemoteFile -> GetRemoteFile -> Bool
Eq, Int -> GetRemoteFile -> ShowS
[GetRemoteFile] -> ShowS
GetRemoteFile -> String
(Int -> GetRemoteFile -> ShowS)
-> (GetRemoteFile -> String)
-> ([GetRemoteFile] -> ShowS)
-> Show GetRemoteFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetRemoteFile -> ShowS
showsPrec :: Int -> GetRemoteFile -> ShowS
$cshow :: GetRemoteFile -> String
show :: GetRemoteFile -> String
$cshowList :: [GetRemoteFile] -> ShowS
showList :: [GetRemoteFile] -> ShowS
Show)

instance I.ShortShow GetRemoteFile where
  shortShow :: GetRemoteFile -> String
shortShow
    GetRemoteFile
      { remote_file_id :: GetRemoteFile -> Maybe Text
remote_file_id = Maybe Text
remote_file_id_
      , file_type :: GetRemoteFile -> Maybe FileType
file_type      = Maybe FileType
file_type_
      }
        = String
"GetRemoteFile"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"remote_file_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
remote_file_id_
          , String
"file_type"      String -> Maybe FileType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FileType
file_type_
          ]

instance AT.ToJSON GetRemoteFile where
  toJSON :: GetRemoteFile -> Value
toJSON
    GetRemoteFile
      { remote_file_id :: GetRemoteFile -> Maybe Text
remote_file_id = Maybe Text
remote_file_id_
      , file_type :: GetRemoteFile -> Maybe FileType
file_type      = Maybe FileType
file_type_
      }
        = [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
"getRemoteFile"
          , Key
"remote_file_id" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
remote_file_id_
          , Key
"file_type"      Key -> Maybe FileType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FileType
file_type_
          ]

defaultGetRemoteFile :: GetRemoteFile
defaultGetRemoteFile :: GetRemoteFile
defaultGetRemoteFile =
  GetRemoteFile
    { remote_file_id :: Maybe Text
remote_file_id = Maybe Text
forall a. Maybe a
Nothing
    , file_type :: Maybe FileType
file_type      = Maybe FileType
forall a. Maybe a
Nothing
    }