{-# 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.WorkMail.UpdatePrimaryEmailAddress
-- 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)
--
-- Updates the primary email for a user, group, or resource. The current
-- email is moved into the list of aliases (or swapped between an existing
-- alias and the current primary email), and the email provided in the
-- input is promoted as the primary.
module Amazonka.WorkMail.UpdatePrimaryEmailAddress
  ( -- * Creating a Request
    UpdatePrimaryEmailAddress (..),
    newUpdatePrimaryEmailAddress,

    -- * Request Lenses
    updatePrimaryEmailAddress_organizationId,
    updatePrimaryEmailAddress_entityId,
    updatePrimaryEmailAddress_email,

    -- * Destructuring the Response
    UpdatePrimaryEmailAddressResponse (..),
    newUpdatePrimaryEmailAddressResponse,

    -- * Response Lenses
    updatePrimaryEmailAddressResponse_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.WorkMail.Types

-- | /See:/ 'newUpdatePrimaryEmailAddress' smart constructor.
data UpdatePrimaryEmailAddress = UpdatePrimaryEmailAddress'
  { -- | The organization that contains the user, group, or resource to update.
    UpdatePrimaryEmailAddress -> Text
organizationId :: Prelude.Text,
    -- | The user, group, or resource to update.
    UpdatePrimaryEmailAddress -> Text
entityId :: Prelude.Text,
    -- | The value of the email to be updated as primary.
    UpdatePrimaryEmailAddress -> Text
email :: Prelude.Text
  }
  deriving (UpdatePrimaryEmailAddress -> UpdatePrimaryEmailAddress -> Bool
(UpdatePrimaryEmailAddress -> UpdatePrimaryEmailAddress -> Bool)
-> (UpdatePrimaryEmailAddress -> UpdatePrimaryEmailAddress -> Bool)
-> Eq UpdatePrimaryEmailAddress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdatePrimaryEmailAddress -> UpdatePrimaryEmailAddress -> Bool
$c/= :: UpdatePrimaryEmailAddress -> UpdatePrimaryEmailAddress -> Bool
== :: UpdatePrimaryEmailAddress -> UpdatePrimaryEmailAddress -> Bool
$c== :: UpdatePrimaryEmailAddress -> UpdatePrimaryEmailAddress -> Bool
Prelude.Eq, ReadPrec [UpdatePrimaryEmailAddress]
ReadPrec UpdatePrimaryEmailAddress
Int -> ReadS UpdatePrimaryEmailAddress
ReadS [UpdatePrimaryEmailAddress]
(Int -> ReadS UpdatePrimaryEmailAddress)
-> ReadS [UpdatePrimaryEmailAddress]
-> ReadPrec UpdatePrimaryEmailAddress
-> ReadPrec [UpdatePrimaryEmailAddress]
-> Read UpdatePrimaryEmailAddress
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdatePrimaryEmailAddress]
$creadListPrec :: ReadPrec [UpdatePrimaryEmailAddress]
readPrec :: ReadPrec UpdatePrimaryEmailAddress
$creadPrec :: ReadPrec UpdatePrimaryEmailAddress
readList :: ReadS [UpdatePrimaryEmailAddress]
$creadList :: ReadS [UpdatePrimaryEmailAddress]
readsPrec :: Int -> ReadS UpdatePrimaryEmailAddress
$creadsPrec :: Int -> ReadS UpdatePrimaryEmailAddress
Prelude.Read, Int -> UpdatePrimaryEmailAddress -> ShowS
[UpdatePrimaryEmailAddress] -> ShowS
UpdatePrimaryEmailAddress -> String
(Int -> UpdatePrimaryEmailAddress -> ShowS)
-> (UpdatePrimaryEmailAddress -> String)
-> ([UpdatePrimaryEmailAddress] -> ShowS)
-> Show UpdatePrimaryEmailAddress
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdatePrimaryEmailAddress] -> ShowS
$cshowList :: [UpdatePrimaryEmailAddress] -> ShowS
show :: UpdatePrimaryEmailAddress -> String
$cshow :: UpdatePrimaryEmailAddress -> String
showsPrec :: Int -> UpdatePrimaryEmailAddress -> ShowS
$cshowsPrec :: Int -> UpdatePrimaryEmailAddress -> ShowS
Prelude.Show, (forall x.
 UpdatePrimaryEmailAddress -> Rep UpdatePrimaryEmailAddress x)
-> (forall x.
    Rep UpdatePrimaryEmailAddress x -> UpdatePrimaryEmailAddress)
-> Generic UpdatePrimaryEmailAddress
forall x.
Rep UpdatePrimaryEmailAddress x -> UpdatePrimaryEmailAddress
forall x.
UpdatePrimaryEmailAddress -> Rep UpdatePrimaryEmailAddress x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdatePrimaryEmailAddress x -> UpdatePrimaryEmailAddress
$cfrom :: forall x.
UpdatePrimaryEmailAddress -> Rep UpdatePrimaryEmailAddress x
Prelude.Generic)

-- |
-- Create a value of 'UpdatePrimaryEmailAddress' 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:
--
-- 'organizationId', 'updatePrimaryEmailAddress_organizationId' - The organization that contains the user, group, or resource to update.
--
-- 'entityId', 'updatePrimaryEmailAddress_entityId' - The user, group, or resource to update.
--
-- 'email', 'updatePrimaryEmailAddress_email' - The value of the email to be updated as primary.
newUpdatePrimaryEmailAddress ::
  -- | 'organizationId'
  Prelude.Text ->
  -- | 'entityId'
  Prelude.Text ->
  -- | 'email'
  Prelude.Text ->
  UpdatePrimaryEmailAddress
newUpdatePrimaryEmailAddress :: Text -> Text -> Text -> UpdatePrimaryEmailAddress
newUpdatePrimaryEmailAddress
  Text
pOrganizationId_
  Text
pEntityId_
  Text
pEmail_ =
    UpdatePrimaryEmailAddress' :: Text -> Text -> Text -> UpdatePrimaryEmailAddress
UpdatePrimaryEmailAddress'
      { $sel:organizationId:UpdatePrimaryEmailAddress' :: Text
organizationId =
          Text
pOrganizationId_,
        $sel:entityId:UpdatePrimaryEmailAddress' :: Text
entityId = Text
pEntityId_,
        $sel:email:UpdatePrimaryEmailAddress' :: Text
email = Text
pEmail_
      }

-- | The organization that contains the user, group, or resource to update.
updatePrimaryEmailAddress_organizationId :: Lens.Lens' UpdatePrimaryEmailAddress Prelude.Text
updatePrimaryEmailAddress_organizationId :: (Text -> f Text)
-> UpdatePrimaryEmailAddress -> f UpdatePrimaryEmailAddress
updatePrimaryEmailAddress_organizationId = (UpdatePrimaryEmailAddress -> Text)
-> (UpdatePrimaryEmailAddress -> Text -> UpdatePrimaryEmailAddress)
-> Lens
     UpdatePrimaryEmailAddress UpdatePrimaryEmailAddress Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePrimaryEmailAddress' {Text
organizationId :: Text
$sel:organizationId:UpdatePrimaryEmailAddress' :: UpdatePrimaryEmailAddress -> Text
organizationId} -> Text
organizationId) (\s :: UpdatePrimaryEmailAddress
s@UpdatePrimaryEmailAddress' {} Text
a -> UpdatePrimaryEmailAddress
s {$sel:organizationId:UpdatePrimaryEmailAddress' :: Text
organizationId = Text
a} :: UpdatePrimaryEmailAddress)

-- | The user, group, or resource to update.
updatePrimaryEmailAddress_entityId :: Lens.Lens' UpdatePrimaryEmailAddress Prelude.Text
updatePrimaryEmailAddress_entityId :: (Text -> f Text)
-> UpdatePrimaryEmailAddress -> f UpdatePrimaryEmailAddress
updatePrimaryEmailAddress_entityId = (UpdatePrimaryEmailAddress -> Text)
-> (UpdatePrimaryEmailAddress -> Text -> UpdatePrimaryEmailAddress)
-> Lens
     UpdatePrimaryEmailAddress UpdatePrimaryEmailAddress Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePrimaryEmailAddress' {Text
entityId :: Text
$sel:entityId:UpdatePrimaryEmailAddress' :: UpdatePrimaryEmailAddress -> Text
entityId} -> Text
entityId) (\s :: UpdatePrimaryEmailAddress
s@UpdatePrimaryEmailAddress' {} Text
a -> UpdatePrimaryEmailAddress
s {$sel:entityId:UpdatePrimaryEmailAddress' :: Text
entityId = Text
a} :: UpdatePrimaryEmailAddress)

-- | The value of the email to be updated as primary.
updatePrimaryEmailAddress_email :: Lens.Lens' UpdatePrimaryEmailAddress Prelude.Text
updatePrimaryEmailAddress_email :: (Text -> f Text)
-> UpdatePrimaryEmailAddress -> f UpdatePrimaryEmailAddress
updatePrimaryEmailAddress_email = (UpdatePrimaryEmailAddress -> Text)
-> (UpdatePrimaryEmailAddress -> Text -> UpdatePrimaryEmailAddress)
-> Lens
     UpdatePrimaryEmailAddress UpdatePrimaryEmailAddress Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePrimaryEmailAddress' {Text
email :: Text
$sel:email:UpdatePrimaryEmailAddress' :: UpdatePrimaryEmailAddress -> Text
email} -> Text
email) (\s :: UpdatePrimaryEmailAddress
s@UpdatePrimaryEmailAddress' {} Text
a -> UpdatePrimaryEmailAddress
s {$sel:email:UpdatePrimaryEmailAddress' :: Text
email = Text
a} :: UpdatePrimaryEmailAddress)

instance Core.AWSRequest UpdatePrimaryEmailAddress where
  type
    AWSResponse UpdatePrimaryEmailAddress =
      UpdatePrimaryEmailAddressResponse
  request :: UpdatePrimaryEmailAddress -> Request UpdatePrimaryEmailAddress
request = Service
-> UpdatePrimaryEmailAddress -> Request UpdatePrimaryEmailAddress
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdatePrimaryEmailAddress
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdatePrimaryEmailAddress)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdatePrimaryEmailAddress))
-> Logger
-> Service
-> Proxy UpdatePrimaryEmailAddress
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdatePrimaryEmailAddress)))
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 -> UpdatePrimaryEmailAddressResponse
UpdatePrimaryEmailAddressResponse'
            (Int -> UpdatePrimaryEmailAddressResponse)
-> Either String Int
-> Either String UpdatePrimaryEmailAddressResponse
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 UpdatePrimaryEmailAddress

instance Prelude.NFData UpdatePrimaryEmailAddress

instance Core.ToHeaders UpdatePrimaryEmailAddress where
  toHeaders :: UpdatePrimaryEmailAddress -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdatePrimaryEmailAddress -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"WorkMailService.UpdatePrimaryEmailAddress" ::
                          Prelude.ByteString
                      ),
            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 UpdatePrimaryEmailAddress where
  toJSON :: UpdatePrimaryEmailAddress -> Value
toJSON UpdatePrimaryEmailAddress' {Text
email :: Text
entityId :: Text
organizationId :: Text
$sel:email:UpdatePrimaryEmailAddress' :: UpdatePrimaryEmailAddress -> Text
$sel:entityId:UpdatePrimaryEmailAddress' :: UpdatePrimaryEmailAddress -> Text
$sel:organizationId:UpdatePrimaryEmailAddress' :: UpdatePrimaryEmailAddress -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"OrganizationId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
organizationId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"EntityId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
entityId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Email" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
email)
          ]
      )

instance Core.ToPath UpdatePrimaryEmailAddress where
  toPath :: UpdatePrimaryEmailAddress -> ByteString
toPath = ByteString -> UpdatePrimaryEmailAddress -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'UpdatePrimaryEmailAddressResponse' 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', 'updatePrimaryEmailAddressResponse_httpStatus' - The response's http status code.
newUpdatePrimaryEmailAddressResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdatePrimaryEmailAddressResponse
newUpdatePrimaryEmailAddressResponse :: Int -> UpdatePrimaryEmailAddressResponse
newUpdatePrimaryEmailAddressResponse Int
pHttpStatus_ =
  UpdatePrimaryEmailAddressResponse' :: Int -> UpdatePrimaryEmailAddressResponse
UpdatePrimaryEmailAddressResponse'
    { $sel:httpStatus:UpdatePrimaryEmailAddressResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance
  Prelude.NFData
    UpdatePrimaryEmailAddressResponse