{-# 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.RegisterMailDomain
-- 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)
--
-- Registers a new domain in Amazon WorkMail and SES, and configures it for
-- use by WorkMail. Emails received by SES for this domain are routed to
-- the specified WorkMail organization, and WorkMail has permanent
-- permission to use the specified domain for sending your users\' emails.
module Amazonka.WorkMail.RegisterMailDomain
  ( -- * Creating a Request
    RegisterMailDomain (..),
    newRegisterMailDomain,

    -- * Request Lenses
    registerMailDomain_clientToken,
    registerMailDomain_organizationId,
    registerMailDomain_domainName,

    -- * Destructuring the Response
    RegisterMailDomainResponse (..),
    newRegisterMailDomainResponse,

    -- * Response Lenses
    registerMailDomainResponse_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:/ 'newRegisterMailDomain' smart constructor.
data RegisterMailDomain = RegisterMailDomain'
  { -- | Idempotency token used when retrying requests.
    RegisterMailDomain -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The Amazon WorkMail organization under which you\'re creating the
    -- domain.
    RegisterMailDomain -> Text
organizationId :: Prelude.Text,
    -- | The name of the mail domain to create in Amazon WorkMail and SES.
    RegisterMailDomain -> Text
domainName :: Prelude.Text
  }
  deriving (RegisterMailDomain -> RegisterMailDomain -> Bool
(RegisterMailDomain -> RegisterMailDomain -> Bool)
-> (RegisterMailDomain -> RegisterMailDomain -> Bool)
-> Eq RegisterMailDomain
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterMailDomain -> RegisterMailDomain -> Bool
$c/= :: RegisterMailDomain -> RegisterMailDomain -> Bool
== :: RegisterMailDomain -> RegisterMailDomain -> Bool
$c== :: RegisterMailDomain -> RegisterMailDomain -> Bool
Prelude.Eq, ReadPrec [RegisterMailDomain]
ReadPrec RegisterMailDomain
Int -> ReadS RegisterMailDomain
ReadS [RegisterMailDomain]
(Int -> ReadS RegisterMailDomain)
-> ReadS [RegisterMailDomain]
-> ReadPrec RegisterMailDomain
-> ReadPrec [RegisterMailDomain]
-> Read RegisterMailDomain
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterMailDomain]
$creadListPrec :: ReadPrec [RegisterMailDomain]
readPrec :: ReadPrec RegisterMailDomain
$creadPrec :: ReadPrec RegisterMailDomain
readList :: ReadS [RegisterMailDomain]
$creadList :: ReadS [RegisterMailDomain]
readsPrec :: Int -> ReadS RegisterMailDomain
$creadsPrec :: Int -> ReadS RegisterMailDomain
Prelude.Read, Int -> RegisterMailDomain -> ShowS
[RegisterMailDomain] -> ShowS
RegisterMailDomain -> String
(Int -> RegisterMailDomain -> ShowS)
-> (RegisterMailDomain -> String)
-> ([RegisterMailDomain] -> ShowS)
-> Show RegisterMailDomain
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterMailDomain] -> ShowS
$cshowList :: [RegisterMailDomain] -> ShowS
show :: RegisterMailDomain -> String
$cshow :: RegisterMailDomain -> String
showsPrec :: Int -> RegisterMailDomain -> ShowS
$cshowsPrec :: Int -> RegisterMailDomain -> ShowS
Prelude.Show, (forall x. RegisterMailDomain -> Rep RegisterMailDomain x)
-> (forall x. Rep RegisterMailDomain x -> RegisterMailDomain)
-> Generic RegisterMailDomain
forall x. Rep RegisterMailDomain x -> RegisterMailDomain
forall x. RegisterMailDomain -> Rep RegisterMailDomain x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterMailDomain x -> RegisterMailDomain
$cfrom :: forall x. RegisterMailDomain -> Rep RegisterMailDomain x
Prelude.Generic)

-- |
-- Create a value of 'RegisterMailDomain' 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:
--
-- 'clientToken', 'registerMailDomain_clientToken' - Idempotency token used when retrying requests.
--
-- 'organizationId', 'registerMailDomain_organizationId' - The Amazon WorkMail organization under which you\'re creating the
-- domain.
--
-- 'domainName', 'registerMailDomain_domainName' - The name of the mail domain to create in Amazon WorkMail and SES.
newRegisterMailDomain ::
  -- | 'organizationId'
  Prelude.Text ->
  -- | 'domainName'
  Prelude.Text ->
  RegisterMailDomain
newRegisterMailDomain :: Text -> Text -> RegisterMailDomain
newRegisterMailDomain Text
pOrganizationId_ Text
pDomainName_ =
  RegisterMailDomain' :: Maybe Text -> Text -> Text -> RegisterMailDomain
RegisterMailDomain'
    { $sel:clientToken:RegisterMailDomain' :: Maybe Text
clientToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:organizationId:RegisterMailDomain' :: Text
organizationId = Text
pOrganizationId_,
      $sel:domainName:RegisterMailDomain' :: Text
domainName = Text
pDomainName_
    }

-- | Idempotency token used when retrying requests.
registerMailDomain_clientToken :: Lens.Lens' RegisterMailDomain (Prelude.Maybe Prelude.Text)
registerMailDomain_clientToken :: (Maybe Text -> f (Maybe Text))
-> RegisterMailDomain -> f RegisterMailDomain
registerMailDomain_clientToken = (RegisterMailDomain -> Maybe Text)
-> (RegisterMailDomain -> Maybe Text -> RegisterMailDomain)
-> Lens
     RegisterMailDomain RegisterMailDomain (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterMailDomain' {Maybe Text
clientToken :: Maybe Text
$sel:clientToken:RegisterMailDomain' :: RegisterMailDomain -> Maybe Text
clientToken} -> Maybe Text
clientToken) (\s :: RegisterMailDomain
s@RegisterMailDomain' {} Maybe Text
a -> RegisterMailDomain
s {$sel:clientToken:RegisterMailDomain' :: Maybe Text
clientToken = Maybe Text
a} :: RegisterMailDomain)

-- | The Amazon WorkMail organization under which you\'re creating the
-- domain.
registerMailDomain_organizationId :: Lens.Lens' RegisterMailDomain Prelude.Text
registerMailDomain_organizationId :: (Text -> f Text) -> RegisterMailDomain -> f RegisterMailDomain
registerMailDomain_organizationId = (RegisterMailDomain -> Text)
-> (RegisterMailDomain -> Text -> RegisterMailDomain)
-> Lens RegisterMailDomain RegisterMailDomain Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterMailDomain' {Text
organizationId :: Text
$sel:organizationId:RegisterMailDomain' :: RegisterMailDomain -> Text
organizationId} -> Text
organizationId) (\s :: RegisterMailDomain
s@RegisterMailDomain' {} Text
a -> RegisterMailDomain
s {$sel:organizationId:RegisterMailDomain' :: Text
organizationId = Text
a} :: RegisterMailDomain)

-- | The name of the mail domain to create in Amazon WorkMail and SES.
registerMailDomain_domainName :: Lens.Lens' RegisterMailDomain Prelude.Text
registerMailDomain_domainName :: (Text -> f Text) -> RegisterMailDomain -> f RegisterMailDomain
registerMailDomain_domainName = (RegisterMailDomain -> Text)
-> (RegisterMailDomain -> Text -> RegisterMailDomain)
-> Lens RegisterMailDomain RegisterMailDomain Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterMailDomain' {Text
domainName :: Text
$sel:domainName:RegisterMailDomain' :: RegisterMailDomain -> Text
domainName} -> Text
domainName) (\s :: RegisterMailDomain
s@RegisterMailDomain' {} Text
a -> RegisterMailDomain
s {$sel:domainName:RegisterMailDomain' :: Text
domainName = Text
a} :: RegisterMailDomain)

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

instance Prelude.NFData RegisterMailDomain

instance Core.ToHeaders RegisterMailDomain where
  toHeaders :: RegisterMailDomain -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RegisterMailDomain -> 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.RegisterMailDomain" ::
                          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 RegisterMailDomain where
  toJSON :: RegisterMailDomain -> Value
toJSON RegisterMailDomain' {Maybe Text
Text
domainName :: Text
organizationId :: Text
clientToken :: Maybe Text
$sel:domainName:RegisterMailDomain' :: RegisterMailDomain -> Text
$sel:organizationId:RegisterMailDomain' :: RegisterMailDomain -> Text
$sel:clientToken:RegisterMailDomain' :: RegisterMailDomain -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ClientToken" 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
clientToken,
            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
"DomainName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
domainName)
          ]
      )

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

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

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

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

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

instance Prelude.NFData RegisterMailDomainResponse