module TD.Query.ImportContacts
  (ImportContacts(..)
  ) 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

-- | Adds new contacts or edits existing contacts by their phone numbers; contacts' user identifiers are ignored. Returns 'TD.Data.ImportedContacts.ImportedContacts'
data ImportContacts
  = ImportContacts
    { ImportContacts -> Maybe [Contact]
contacts :: Maybe [Contact.Contact] -- ^ The list of contacts to import or edit; contacts' vCard are ignored and are not imported
    }
  deriving (ImportContacts -> ImportContacts -> Bool
(ImportContacts -> ImportContacts -> Bool)
-> (ImportContacts -> ImportContacts -> Bool) -> Eq ImportContacts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ImportContacts -> ImportContacts -> Bool
== :: ImportContacts -> ImportContacts -> Bool
$c/= :: ImportContacts -> ImportContacts -> Bool
/= :: ImportContacts -> ImportContacts -> Bool
Eq, Int -> ImportContacts -> ShowS
[ImportContacts] -> ShowS
ImportContacts -> String
(Int -> ImportContacts -> ShowS)
-> (ImportContacts -> String)
-> ([ImportContacts] -> ShowS)
-> Show ImportContacts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ImportContacts -> ShowS
showsPrec :: Int -> ImportContacts -> ShowS
$cshow :: ImportContacts -> String
show :: ImportContacts -> String
$cshowList :: [ImportContacts] -> ShowS
showList :: [ImportContacts] -> ShowS
Show)

instance I.ShortShow ImportContacts where
  shortShow :: ImportContacts -> String
shortShow
    ImportContacts
      { contacts :: ImportContacts -> Maybe [Contact]
contacts = Maybe [Contact]
contacts_
      }
        = String
"ImportContacts"
          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 ImportContacts where
  toJSON :: ImportContacts -> Value
toJSON
    ImportContacts
      { contacts :: ImportContacts -> 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
"importContacts"
          , 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_
          ]