module TD.Query.ImportMessages
  (ImportMessages(..)
  , defaultImportMessages
  ) where

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

-- | Imports messages exported from another app. Returns 'TD.Data.Ok.Ok'
data ImportMessages
  = ImportMessages
    { ImportMessages -> Maybe Int
chat_id        :: Maybe Int                   -- ^ Identifier of a chat to which the messages will be imported. It must be an identifier of a private chat with a mutual contact or an identifier of a supergroup chat with can_change_info member right
    , ImportMessages -> Maybe InputFile
message_file   :: Maybe InputFile.InputFile   -- ^ File with messages to import. Only inputFileLocal and inputFileGenerated are supported. The file must not be previously uploaded
    , ImportMessages -> Maybe [InputFile]
attached_files :: Maybe [InputFile.InputFile] -- ^ Files used in the imported messages. Only inputFileLocal and inputFileGenerated are supported. The files must not be previously uploaded
    }
  deriving (ImportMessages -> ImportMessages -> Bool
(ImportMessages -> ImportMessages -> Bool)
-> (ImportMessages -> ImportMessages -> Bool) -> Eq ImportMessages
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ImportMessages -> ImportMessages -> Bool
== :: ImportMessages -> ImportMessages -> Bool
$c/= :: ImportMessages -> ImportMessages -> Bool
/= :: ImportMessages -> ImportMessages -> Bool
Eq, Int -> ImportMessages -> ShowS
[ImportMessages] -> ShowS
ImportMessages -> String
(Int -> ImportMessages -> ShowS)
-> (ImportMessages -> String)
-> ([ImportMessages] -> ShowS)
-> Show ImportMessages
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ImportMessages -> ShowS
showsPrec :: Int -> ImportMessages -> ShowS
$cshow :: ImportMessages -> String
show :: ImportMessages -> String
$cshowList :: [ImportMessages] -> ShowS
showList :: [ImportMessages] -> ShowS
Show)

instance I.ShortShow ImportMessages where
  shortShow :: ImportMessages -> String
shortShow
    ImportMessages
      { chat_id :: ImportMessages -> Maybe Int
chat_id        = Maybe Int
chat_id_
      , message_file :: ImportMessages -> Maybe InputFile
message_file   = Maybe InputFile
message_file_
      , attached_files :: ImportMessages -> Maybe [InputFile]
attached_files = Maybe [InputFile]
attached_files_
      }
        = String
"ImportMessages"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"chat_id"        String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"message_file"   String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
message_file_
          , String
"attached_files" String -> Maybe [InputFile] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [InputFile]
attached_files_
          ]

instance AT.ToJSON ImportMessages where
  toJSON :: ImportMessages -> Value
toJSON
    ImportMessages
      { chat_id :: ImportMessages -> Maybe Int
chat_id        = Maybe Int
chat_id_
      , message_file :: ImportMessages -> Maybe InputFile
message_file   = Maybe InputFile
message_file_
      , attached_files :: ImportMessages -> Maybe [InputFile]
attached_files = Maybe [InputFile]
attached_files_
      }
        = [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
"importMessages"
          , 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_file"   Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
message_file_
          , Key
"attached_files" Key -> Maybe [InputFile] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [InputFile]
attached_files_
          ]

defaultImportMessages :: ImportMessages
defaultImportMessages :: ImportMessages
defaultImportMessages =
  ImportMessages
    { chat_id :: Maybe Int
chat_id        = Maybe Int
forall a. Maybe a
Nothing
    , message_file :: Maybe InputFile
message_file   = Maybe InputFile
forall a. Maybe a
Nothing
    , attached_files :: Maybe [InputFile]
attached_files = Maybe [InputFile]
forall a. Maybe a
Nothing
    }