{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SESV2.CreateContact
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a contact, which is an end-user who is receiving the email, and
-- adds them to a contact list.
module Amazonka.SESV2.CreateContact
  ( -- * Creating a Request
    CreateContact (..),
    newCreateContact,

    -- * Request Lenses
    createContact_unsubscribeAll,
    createContact_attributesData,
    createContact_topicPreferences,
    createContact_contactListName,
    createContact_emailAddress,

    -- * Destructuring the Response
    CreateContactResponse (..),
    newCreateContactResponse,

    -- * Response Lenses
    createContactResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SESV2.Types

-- | /See:/ 'newCreateContact' smart constructor.
data CreateContact = CreateContact'
  { -- | A boolean value status noting if the contact is unsubscribed from all
    -- contact list topics.
    CreateContact -> Maybe Bool
unsubscribeAll :: Prelude.Maybe Prelude.Bool,
    -- | The attribute data attached to a contact.
    CreateContact -> Maybe Text
attributesData :: Prelude.Maybe Prelude.Text,
    -- | The contact\'s preferences for being opted-in to or opted-out of topics.
    CreateContact -> Maybe [TopicPreference]
topicPreferences :: Prelude.Maybe [TopicPreference],
    -- | The name of the contact list to which the contact should be added.
    CreateContact -> Text
contactListName :: Prelude.Text,
    -- | The contact\'s email address.
    CreateContact -> Text
emailAddress :: Prelude.Text
  }
  deriving (CreateContact -> CreateContact -> Bool
(CreateContact -> CreateContact -> Bool)
-> (CreateContact -> CreateContact -> Bool) -> Eq CreateContact
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateContact -> CreateContact -> Bool
$c/= :: CreateContact -> CreateContact -> Bool
== :: CreateContact -> CreateContact -> Bool
$c== :: CreateContact -> CreateContact -> Bool
Prelude.Eq, ReadPrec [CreateContact]
ReadPrec CreateContact
Int -> ReadS CreateContact
ReadS [CreateContact]
(Int -> ReadS CreateContact)
-> ReadS [CreateContact]
-> ReadPrec CreateContact
-> ReadPrec [CreateContact]
-> Read CreateContact
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateContact]
$creadListPrec :: ReadPrec [CreateContact]
readPrec :: ReadPrec CreateContact
$creadPrec :: ReadPrec CreateContact
readList :: ReadS [CreateContact]
$creadList :: ReadS [CreateContact]
readsPrec :: Int -> ReadS CreateContact
$creadsPrec :: Int -> ReadS CreateContact
Prelude.Read, Int -> CreateContact -> ShowS
[CreateContact] -> ShowS
CreateContact -> String
(Int -> CreateContact -> ShowS)
-> (CreateContact -> String)
-> ([CreateContact] -> ShowS)
-> Show CreateContact
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateContact] -> ShowS
$cshowList :: [CreateContact] -> ShowS
show :: CreateContact -> String
$cshow :: CreateContact -> String
showsPrec :: Int -> CreateContact -> ShowS
$cshowsPrec :: Int -> CreateContact -> ShowS
Prelude.Show, (forall x. CreateContact -> Rep CreateContact x)
-> (forall x. Rep CreateContact x -> CreateContact)
-> Generic CreateContact
forall x. Rep CreateContact x -> CreateContact
forall x. CreateContact -> Rep CreateContact x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateContact x -> CreateContact
$cfrom :: forall x. CreateContact -> Rep CreateContact x
Prelude.Generic)

-- |
-- Create a value of 'CreateContact' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'unsubscribeAll', 'createContact_unsubscribeAll' - A boolean value status noting if the contact is unsubscribed from all
-- contact list topics.
--
-- 'attributesData', 'createContact_attributesData' - The attribute data attached to a contact.
--
-- 'topicPreferences', 'createContact_topicPreferences' - The contact\'s preferences for being opted-in to or opted-out of topics.
--
-- 'contactListName', 'createContact_contactListName' - The name of the contact list to which the contact should be added.
--
-- 'emailAddress', 'createContact_emailAddress' - The contact\'s email address.
newCreateContact ::
  -- | 'contactListName'
  Prelude.Text ->
  -- | 'emailAddress'
  Prelude.Text ->
  CreateContact
newCreateContact :: Text -> Text -> CreateContact
newCreateContact Text
pContactListName_ Text
pEmailAddress_ =
  CreateContact' :: Maybe Bool
-> Maybe Text
-> Maybe [TopicPreference]
-> Text
-> Text
-> CreateContact
CreateContact'
    { $sel:unsubscribeAll:CreateContact' :: Maybe Bool
unsubscribeAll = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:attributesData:CreateContact' :: Maybe Text
attributesData = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:topicPreferences:CreateContact' :: Maybe [TopicPreference]
topicPreferences = Maybe [TopicPreference]
forall a. Maybe a
Prelude.Nothing,
      $sel:contactListName:CreateContact' :: Text
contactListName = Text
pContactListName_,
      $sel:emailAddress:CreateContact' :: Text
emailAddress = Text
pEmailAddress_
    }

-- | A boolean value status noting if the contact is unsubscribed from all
-- contact list topics.
createContact_unsubscribeAll :: Lens.Lens' CreateContact (Prelude.Maybe Prelude.Bool)
createContact_unsubscribeAll :: (Maybe Bool -> f (Maybe Bool)) -> CreateContact -> f CreateContact
createContact_unsubscribeAll = (CreateContact -> Maybe Bool)
-> (CreateContact -> Maybe Bool -> CreateContact)
-> Lens CreateContact CreateContact (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateContact' {Maybe Bool
unsubscribeAll :: Maybe Bool
$sel:unsubscribeAll:CreateContact' :: CreateContact -> Maybe Bool
unsubscribeAll} -> Maybe Bool
unsubscribeAll) (\s :: CreateContact
s@CreateContact' {} Maybe Bool
a -> CreateContact
s {$sel:unsubscribeAll:CreateContact' :: Maybe Bool
unsubscribeAll = Maybe Bool
a} :: CreateContact)

-- | The attribute data attached to a contact.
createContact_attributesData :: Lens.Lens' CreateContact (Prelude.Maybe Prelude.Text)
createContact_attributesData :: (Maybe Text -> f (Maybe Text)) -> CreateContact -> f CreateContact
createContact_attributesData = (CreateContact -> Maybe Text)
-> (CreateContact -> Maybe Text -> CreateContact)
-> Lens CreateContact CreateContact (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateContact' {Maybe Text
attributesData :: Maybe Text
$sel:attributesData:CreateContact' :: CreateContact -> Maybe Text
attributesData} -> Maybe Text
attributesData) (\s :: CreateContact
s@CreateContact' {} Maybe Text
a -> CreateContact
s {$sel:attributesData:CreateContact' :: Maybe Text
attributesData = Maybe Text
a} :: CreateContact)

-- | The contact\'s preferences for being opted-in to or opted-out of topics.
createContact_topicPreferences :: Lens.Lens' CreateContact (Prelude.Maybe [TopicPreference])
createContact_topicPreferences :: (Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
-> CreateContact -> f CreateContact
createContact_topicPreferences = (CreateContact -> Maybe [TopicPreference])
-> (CreateContact -> Maybe [TopicPreference] -> CreateContact)
-> Lens
     CreateContact
     CreateContact
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateContact' {Maybe [TopicPreference]
topicPreferences :: Maybe [TopicPreference]
$sel:topicPreferences:CreateContact' :: CreateContact -> Maybe [TopicPreference]
topicPreferences} -> Maybe [TopicPreference]
topicPreferences) (\s :: CreateContact
s@CreateContact' {} Maybe [TopicPreference]
a -> CreateContact
s {$sel:topicPreferences:CreateContact' :: Maybe [TopicPreference]
topicPreferences = Maybe [TopicPreference]
a} :: CreateContact) ((Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
 -> CreateContact -> f CreateContact)
-> ((Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
    -> Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
-> (Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
-> CreateContact
-> f CreateContact
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
-> Iso
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the contact list to which the contact should be added.
createContact_contactListName :: Lens.Lens' CreateContact Prelude.Text
createContact_contactListName :: (Text -> f Text) -> CreateContact -> f CreateContact
createContact_contactListName = (CreateContact -> Text)
-> (CreateContact -> Text -> CreateContact)
-> Lens CreateContact CreateContact Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateContact' {Text
contactListName :: Text
$sel:contactListName:CreateContact' :: CreateContact -> Text
contactListName} -> Text
contactListName) (\s :: CreateContact
s@CreateContact' {} Text
a -> CreateContact
s {$sel:contactListName:CreateContact' :: Text
contactListName = Text
a} :: CreateContact)

-- | The contact\'s email address.
createContact_emailAddress :: Lens.Lens' CreateContact Prelude.Text
createContact_emailAddress :: (Text -> f Text) -> CreateContact -> f CreateContact
createContact_emailAddress = (CreateContact -> Text)
-> (CreateContact -> Text -> CreateContact)
-> Lens CreateContact CreateContact Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateContact' {Text
emailAddress :: Text
$sel:emailAddress:CreateContact' :: CreateContact -> Text
emailAddress} -> Text
emailAddress) (\s :: CreateContact
s@CreateContact' {} Text
a -> CreateContact
s {$sel:emailAddress:CreateContact' :: Text
emailAddress = Text
a} :: CreateContact)

instance Core.AWSRequest CreateContact where
  type
    AWSResponse CreateContact =
      CreateContactResponse
  request :: CreateContact -> Request CreateContact
request = Service -> CreateContact -> Request CreateContact
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateContact
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateContact)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreateContact))
-> Logger
-> Service
-> Proxy CreateContact
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateContact)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> CreateContactResponse
CreateContactResponse'
            (Int -> CreateContactResponse)
-> Either String Int -> Either String CreateContactResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateContact

instance Prelude.NFData CreateContact

instance Core.ToHeaders CreateContact where
  toHeaders :: CreateContact -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateContact -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateContact where
  toJSON :: CreateContact -> Value
toJSON CreateContact' {Maybe Bool
Maybe [TopicPreference]
Maybe Text
Text
emailAddress :: Text
contactListName :: Text
topicPreferences :: Maybe [TopicPreference]
attributesData :: Maybe Text
unsubscribeAll :: Maybe Bool
$sel:emailAddress:CreateContact' :: CreateContact -> Text
$sel:contactListName:CreateContact' :: CreateContact -> Text
$sel:topicPreferences:CreateContact' :: CreateContact -> Maybe [TopicPreference]
$sel:attributesData:CreateContact' :: CreateContact -> Maybe Text
$sel:unsubscribeAll:CreateContact' :: CreateContact -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"UnsubscribeAll" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
unsubscribeAll,
            (Text
"AttributesData" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
attributesData,
            (Text
"TopicPreferences" Text -> [TopicPreference] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([TopicPreference] -> Pair)
-> Maybe [TopicPreference] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [TopicPreference]
topicPreferences,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"EmailAddress" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
emailAddress)
          ]
      )

instance Core.ToPath CreateContact where
  toPath :: CreateContact -> ByteString
toPath CreateContact' {Maybe Bool
Maybe [TopicPreference]
Maybe Text
Text
emailAddress :: Text
contactListName :: Text
topicPreferences :: Maybe [TopicPreference]
attributesData :: Maybe Text
unsubscribeAll :: Maybe Bool
$sel:emailAddress:CreateContact' :: CreateContact -> Text
$sel:contactListName:CreateContact' :: CreateContact -> Text
$sel:topicPreferences:CreateContact' :: CreateContact -> Maybe [TopicPreference]
$sel:attributesData:CreateContact' :: CreateContact -> Maybe Text
$sel:unsubscribeAll:CreateContact' :: CreateContact -> Maybe Bool
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/v2/email/contact-lists/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
contactListName,
        ByteString
"/contacts"
      ]

instance Core.ToQuery CreateContact where
  toQuery :: CreateContact -> QueryString
toQuery = QueryString -> CreateContact -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateContactResponse' smart constructor.
data CreateContactResponse = CreateContactResponse'
  { -- | The response's http status code.
    CreateContactResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateContactResponse -> CreateContactResponse -> Bool
(CreateContactResponse -> CreateContactResponse -> Bool)
-> (CreateContactResponse -> CreateContactResponse -> Bool)
-> Eq CreateContactResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateContactResponse -> CreateContactResponse -> Bool
$c/= :: CreateContactResponse -> CreateContactResponse -> Bool
== :: CreateContactResponse -> CreateContactResponse -> Bool
$c== :: CreateContactResponse -> CreateContactResponse -> Bool
Prelude.Eq, ReadPrec [CreateContactResponse]
ReadPrec CreateContactResponse
Int -> ReadS CreateContactResponse
ReadS [CreateContactResponse]
(Int -> ReadS CreateContactResponse)
-> ReadS [CreateContactResponse]
-> ReadPrec CreateContactResponse
-> ReadPrec [CreateContactResponse]
-> Read CreateContactResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateContactResponse]
$creadListPrec :: ReadPrec [CreateContactResponse]
readPrec :: ReadPrec CreateContactResponse
$creadPrec :: ReadPrec CreateContactResponse
readList :: ReadS [CreateContactResponse]
$creadList :: ReadS [CreateContactResponse]
readsPrec :: Int -> ReadS CreateContactResponse
$creadsPrec :: Int -> ReadS CreateContactResponse
Prelude.Read, Int -> CreateContactResponse -> ShowS
[CreateContactResponse] -> ShowS
CreateContactResponse -> String
(Int -> CreateContactResponse -> ShowS)
-> (CreateContactResponse -> String)
-> ([CreateContactResponse] -> ShowS)
-> Show CreateContactResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateContactResponse] -> ShowS
$cshowList :: [CreateContactResponse] -> ShowS
show :: CreateContactResponse -> String
$cshow :: CreateContactResponse -> String
showsPrec :: Int -> CreateContactResponse -> ShowS
$cshowsPrec :: Int -> CreateContactResponse -> ShowS
Prelude.Show, (forall x. CreateContactResponse -> Rep CreateContactResponse x)
-> (forall x. Rep CreateContactResponse x -> CreateContactResponse)
-> Generic CreateContactResponse
forall x. Rep CreateContactResponse x -> CreateContactResponse
forall x. CreateContactResponse -> Rep CreateContactResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateContactResponse x -> CreateContactResponse
$cfrom :: forall x. CreateContactResponse -> Rep CreateContactResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateContactResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'httpStatus', 'createContactResponse_httpStatus' - The response's http status code.
newCreateContactResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateContactResponse
newCreateContactResponse :: Int -> CreateContactResponse
newCreateContactResponse Int
pHttpStatus_ =
  CreateContactResponse' :: Int -> CreateContactResponse
CreateContactResponse' {$sel:httpStatus:CreateContactResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
createContactResponse_httpStatus :: Lens.Lens' CreateContactResponse Prelude.Int
createContactResponse_httpStatus :: (Int -> f Int) -> CreateContactResponse -> f CreateContactResponse
createContactResponse_httpStatus = (CreateContactResponse -> Int)
-> (CreateContactResponse -> Int -> CreateContactResponse)
-> Lens CreateContactResponse CreateContactResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateContactResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateContactResponse' :: CreateContactResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateContactResponse
s@CreateContactResponse' {} Int
a -> CreateContactResponse
s {$sel:httpStatus:CreateContactResponse' :: Int
httpStatus = Int
a} :: CreateContactResponse)

instance Prelude.NFData CreateContactResponse