module TD.Data.ImportedContact
  ( ImportedContact(..)    
  , defaultImportedContact 
  ) 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.FormattedText as FormattedText

data ImportedContact
  = ImportedContact -- ^ Describes a contact to import
    { ImportedContact -> Maybe Text
phone_number :: Maybe T.Text                      -- ^ Phone number of the user
    , ImportedContact -> Maybe Text
first_name   :: Maybe T.Text                      -- ^ First name of the user; 1-64 characters
    , ImportedContact -> Maybe Text
last_name    :: Maybe T.Text                      -- ^ Last name of the user; 0-64 characters
    , ImportedContact -> Maybe FormattedText
note         :: Maybe FormattedText.FormattedText -- ^ Note to add about the user; 0-getOption("user_note_text_length_max") characters. Only Bold, Italic, Underline, Strikethrough, Spoiler, and CustomEmoji entities are allowed; pass null to keep the current user's note
    }
  deriving (ImportedContact -> ImportedContact -> Bool
(ImportedContact -> ImportedContact -> Bool)
-> (ImportedContact -> ImportedContact -> Bool)
-> Eq ImportedContact
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ImportedContact -> ImportedContact -> Bool
== :: ImportedContact -> ImportedContact -> Bool
$c/= :: ImportedContact -> ImportedContact -> Bool
/= :: ImportedContact -> ImportedContact -> Bool
Eq, Int -> ImportedContact -> ShowS
[ImportedContact] -> ShowS
ImportedContact -> String
(Int -> ImportedContact -> ShowS)
-> (ImportedContact -> String)
-> ([ImportedContact] -> ShowS)
-> Show ImportedContact
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ImportedContact -> ShowS
showsPrec :: Int -> ImportedContact -> ShowS
$cshow :: ImportedContact -> String
show :: ImportedContact -> String
$cshowList :: [ImportedContact] -> ShowS
showList :: [ImportedContact] -> ShowS
Show)

instance I.ShortShow ImportedContact where
  shortShow :: ImportedContact -> String
shortShow ImportedContact
    { phone_number :: ImportedContact -> Maybe Text
phone_number = Maybe Text
phone_number_
    , first_name :: ImportedContact -> Maybe Text
first_name   = Maybe Text
first_name_
    , last_name :: ImportedContact -> Maybe Text
last_name    = Maybe Text
last_name_
    , note :: ImportedContact -> Maybe FormattedText
note         = Maybe FormattedText
note_
    }
      = String
"ImportedContact"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"phone_number" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
phone_number_
        , String
"first_name"   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
first_name_
        , String
"last_name"    String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
last_name_
        , String
"note"         String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
note_
        ]

instance AT.FromJSON ImportedContact where
  parseJSON :: Value -> Parser ImportedContact
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"importedContact" -> Value -> Parser ImportedContact
parseImportedContact Value
v
      String
_                 -> Parser ImportedContact
forall a. Monoid a => a
mempty
    
    where
      parseImportedContact :: A.Value -> AT.Parser ImportedContact
      parseImportedContact :: Value -> Parser ImportedContact
parseImportedContact = String
-> (Object -> Parser ImportedContact)
-> Value
-> Parser ImportedContact
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ImportedContact" ((Object -> Parser ImportedContact)
 -> Value -> Parser ImportedContact)
-> (Object -> Parser ImportedContact)
-> Value
-> Parser ImportedContact
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
phone_number_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"phone_number"
        Maybe Text
first_name_   <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"first_name"
        Maybe Text
last_name_    <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"last_name"
        Maybe FormattedText
note_         <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"note"
        ImportedContact -> Parser ImportedContact
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ImportedContact -> Parser ImportedContact)
-> ImportedContact -> Parser ImportedContact
forall a b. (a -> b) -> a -> b
$ ImportedContact
          { phone_number :: Maybe Text
phone_number = Maybe Text
phone_number_
          , first_name :: Maybe Text
first_name   = Maybe Text
first_name_
          , last_name :: Maybe Text
last_name    = Maybe Text
last_name_
          , note :: Maybe FormattedText
note         = Maybe FormattedText
note_
          }
  parseJSON Value
_ = Parser ImportedContact
forall a. Monoid a => a
mempty

instance AT.ToJSON ImportedContact where
  toJSON :: ImportedContact -> Value
toJSON ImportedContact
    { phone_number :: ImportedContact -> Maybe Text
phone_number = Maybe Text
phone_number_
    , first_name :: ImportedContact -> Maybe Text
first_name   = Maybe Text
first_name_
    , last_name :: ImportedContact -> Maybe Text
last_name    = Maybe Text
last_name_
    , note :: ImportedContact -> Maybe FormattedText
note         = Maybe FormattedText
note_
    }
      = [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
"importedContact"
        , Key
"phone_number" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
phone_number_
        , Key
"first_name"   Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
first_name_
        , Key
"last_name"    Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
last_name_
        , Key
"note"         Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
note_
        ]

defaultImportedContact :: ImportedContact
defaultImportedContact :: ImportedContact
defaultImportedContact =
  ImportedContact
    { phone_number :: Maybe Text
phone_number = Maybe Text
forall a. Maybe a
Nothing
    , first_name :: Maybe Text
first_name   = Maybe Text
forall a. Maybe a
Nothing
    , last_name :: Maybe Text
last_name    = Maybe Text
forall a. Maybe a
Nothing
    , note :: Maybe FormattedText
note         = Maybe FormattedText
forall a. Maybe a
Nothing
    }