module TD.Query.AddContact
  (AddContact(..)
  , defaultAddContact
  ) 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 a user to the contact list or edits an existing contact by their user identifier. Returns 'TD.Data.Ok.Ok'
data AddContact
  = AddContact
    { AddContact -> Maybe Contact
contact            :: Maybe Contact.Contact -- ^ The contact to add or edit; phone number may be empty and needs to be specified only if known, vCard is ignored
    , AddContact -> Maybe Bool
share_phone_number :: Maybe Bool            -- ^ Pass true to share the current user's phone number with the new contact. A corresponding rule to userPrivacySettingShowPhoneNumber will be added if needed. Use the field userFullInfo.need_phone_number_privacy_exception to check whether the current user needs to be asked to share their phone number
    }
  deriving (AddContact -> AddContact -> Bool
(AddContact -> AddContact -> Bool)
-> (AddContact -> AddContact -> Bool) -> Eq AddContact
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AddContact -> AddContact -> Bool
== :: AddContact -> AddContact -> Bool
$c/= :: AddContact -> AddContact -> Bool
/= :: AddContact -> AddContact -> Bool
Eq, Int -> AddContact -> ShowS
[AddContact] -> ShowS
AddContact -> String
(Int -> AddContact -> ShowS)
-> (AddContact -> String)
-> ([AddContact] -> ShowS)
-> Show AddContact
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddContact -> ShowS
showsPrec :: Int -> AddContact -> ShowS
$cshow :: AddContact -> String
show :: AddContact -> String
$cshowList :: [AddContact] -> ShowS
showList :: [AddContact] -> ShowS
Show)

instance I.ShortShow AddContact where
  shortShow :: AddContact -> String
shortShow
    AddContact
      { contact :: AddContact -> Maybe Contact
contact            = Maybe Contact
contact_
      , share_phone_number :: AddContact -> Maybe Bool
share_phone_number = Maybe Bool
share_phone_number_
      }
        = String
"AddContact"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"contact"            String -> Maybe Contact -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Contact
contact_
          , String
"share_phone_number" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
share_phone_number_
          ]

instance AT.ToJSON AddContact where
  toJSON :: AddContact -> Value
toJSON
    AddContact
      { contact :: AddContact -> Maybe Contact
contact            = Maybe Contact
contact_
      , share_phone_number :: AddContact -> Maybe Bool
share_phone_number = Maybe Bool
share_phone_number_
      }
        = [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
"addContact"
          , Key
"contact"            Key -> Maybe Contact -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Contact
contact_
          , Key
"share_phone_number" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
share_phone_number_
          ]

defaultAddContact :: AddContact
defaultAddContact :: AddContact
defaultAddContact =
  AddContact
    { contact :: Maybe Contact
contact            = Maybe Contact
forall a. Maybe a
Nothing
    , share_phone_number :: Maybe Bool
share_phone_number = Maybe Bool
forall a. Maybe a
Nothing
    }