module TD.Query.ChangeImportedContacts
  (ChangeImportedContacts(..)
  ) 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.Contact as Contact

-- | Changes imported contacts using the list of contacts saved on the device. Imports newly added contacts and, if at least the file database is enabled, deletes recently deleted contacts. Query result depends on the result of the previous query, so only one query is possible at the same time. Returns 'TD.Data.ImportedContacts.ImportedContacts'
data ChangeImportedContacts
  = ChangeImportedContacts
    { ChangeImportedContacts -> Maybe [Contact]
contacts :: Maybe [Contact.Contact] -- ^ The new list of contacts, contact's vCard are ignored and are not imported
    }
  deriving (ChangeImportedContacts -> ChangeImportedContacts -> Bool
(ChangeImportedContacts -> ChangeImportedContacts -> Bool)
-> (ChangeImportedContacts -> ChangeImportedContacts -> Bool)
-> Eq ChangeImportedContacts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChangeImportedContacts -> ChangeImportedContacts -> Bool
== :: ChangeImportedContacts -> ChangeImportedContacts -> Bool
$c/= :: ChangeImportedContacts -> ChangeImportedContacts -> Bool
/= :: ChangeImportedContacts -> ChangeImportedContacts -> Bool
Eq, Int -> ChangeImportedContacts -> ShowS
[ChangeImportedContacts] -> ShowS
ChangeImportedContacts -> String
(Int -> ChangeImportedContacts -> ShowS)
-> (ChangeImportedContacts -> String)
-> ([ChangeImportedContacts] -> ShowS)
-> Show ChangeImportedContacts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChangeImportedContacts -> ShowS
showsPrec :: Int -> ChangeImportedContacts -> ShowS
$cshow :: ChangeImportedContacts -> String
show :: ChangeImportedContacts -> String
$cshowList :: [ChangeImportedContacts] -> ShowS
showList :: [ChangeImportedContacts] -> ShowS
Show)

instance I.ShortShow ChangeImportedContacts where
  shortShow :: ChangeImportedContacts -> String
shortShow
    ChangeImportedContacts
      { contacts :: ChangeImportedContacts -> Maybe [Contact]
contacts = Maybe [Contact]
contacts_
      }
        = String
"ChangeImportedContacts"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"contacts" String -> Maybe [Contact] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Contact]
contacts_
          ]

instance AT.ToJSON ChangeImportedContacts where
  toJSON :: ChangeImportedContacts -> Value
toJSON
    ChangeImportedContacts
      { contacts :: ChangeImportedContacts -> Maybe [Contact]
contacts = Maybe [Contact]
contacts_
      }
        = [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
"changeImportedContacts"
          , Key
"contacts" Key -> Maybe [Contact] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Contact]
contacts_
          ]