{-# 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.DeregisterMailDomain
-- 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)
--
-- Removes a domain from Amazon WorkMail, stops email routing to WorkMail,
-- and removes the authorization allowing WorkMail use. SES keeps the
-- domain because other applications may use it. You must first remove any
-- email address used by WorkMail entities before you remove the domain.
module Amazonka.WorkMail.DeregisterMailDomain
  ( -- * Creating a Request
    DeregisterMailDomain (..),
    newDeregisterMailDomain,

    -- * Request Lenses
    deregisterMailDomain_organizationId,
    deregisterMailDomain_domainName,

    -- * Destructuring the Response
    DeregisterMailDomainResponse (..),
    newDeregisterMailDomainResponse,

    -- * Response Lenses
    deregisterMailDomainResponse_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:/ 'newDeregisterMailDomain' smart constructor.
data DeregisterMailDomain = DeregisterMailDomain'
  { -- | The Amazon WorkMail organization for which the domain will be
    -- deregistered.
    DeregisterMailDomain -> Text
organizationId :: Prelude.Text,
    -- | The domain to deregister in WorkMail and SES.
    DeregisterMailDomain -> Text
domainName :: Prelude.Text
  }
  deriving (DeregisterMailDomain -> DeregisterMailDomain -> Bool
(DeregisterMailDomain -> DeregisterMailDomain -> Bool)
-> (DeregisterMailDomain -> DeregisterMailDomain -> Bool)
-> Eq DeregisterMailDomain
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeregisterMailDomain -> DeregisterMailDomain -> Bool
$c/= :: DeregisterMailDomain -> DeregisterMailDomain -> Bool
== :: DeregisterMailDomain -> DeregisterMailDomain -> Bool
$c== :: DeregisterMailDomain -> DeregisterMailDomain -> Bool
Prelude.Eq, ReadPrec [DeregisterMailDomain]
ReadPrec DeregisterMailDomain
Int -> ReadS DeregisterMailDomain
ReadS [DeregisterMailDomain]
(Int -> ReadS DeregisterMailDomain)
-> ReadS [DeregisterMailDomain]
-> ReadPrec DeregisterMailDomain
-> ReadPrec [DeregisterMailDomain]
-> Read DeregisterMailDomain
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeregisterMailDomain]
$creadListPrec :: ReadPrec [DeregisterMailDomain]
readPrec :: ReadPrec DeregisterMailDomain
$creadPrec :: ReadPrec DeregisterMailDomain
readList :: ReadS [DeregisterMailDomain]
$creadList :: ReadS [DeregisterMailDomain]
readsPrec :: Int -> ReadS DeregisterMailDomain
$creadsPrec :: Int -> ReadS DeregisterMailDomain
Prelude.Read, Int -> DeregisterMailDomain -> ShowS
[DeregisterMailDomain] -> ShowS
DeregisterMailDomain -> String
(Int -> DeregisterMailDomain -> ShowS)
-> (DeregisterMailDomain -> String)
-> ([DeregisterMailDomain] -> ShowS)
-> Show DeregisterMailDomain
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeregisterMailDomain] -> ShowS
$cshowList :: [DeregisterMailDomain] -> ShowS
show :: DeregisterMailDomain -> String
$cshow :: DeregisterMailDomain -> String
showsPrec :: Int -> DeregisterMailDomain -> ShowS
$cshowsPrec :: Int -> DeregisterMailDomain -> ShowS
Prelude.Show, (forall x. DeregisterMailDomain -> Rep DeregisterMailDomain x)
-> (forall x. Rep DeregisterMailDomain x -> DeregisterMailDomain)
-> Generic DeregisterMailDomain
forall x. Rep DeregisterMailDomain x -> DeregisterMailDomain
forall x. DeregisterMailDomain -> Rep DeregisterMailDomain x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeregisterMailDomain x -> DeregisterMailDomain
$cfrom :: forall x. DeregisterMailDomain -> Rep DeregisterMailDomain x
Prelude.Generic)

-- |
-- Create a value of 'DeregisterMailDomain' 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', 'deregisterMailDomain_organizationId' - The Amazon WorkMail organization for which the domain will be
-- deregistered.
--
-- 'domainName', 'deregisterMailDomain_domainName' - The domain to deregister in WorkMail and SES.
newDeregisterMailDomain ::
  -- | 'organizationId'
  Prelude.Text ->
  -- | 'domainName'
  Prelude.Text ->
  DeregisterMailDomain
newDeregisterMailDomain :: Text -> Text -> DeregisterMailDomain
newDeregisterMailDomain Text
pOrganizationId_ Text
pDomainName_ =
  DeregisterMailDomain' :: Text -> Text -> DeregisterMailDomain
DeregisterMailDomain'
    { $sel:organizationId:DeregisterMailDomain' :: Text
organizationId =
        Text
pOrganizationId_,
      $sel:domainName:DeregisterMailDomain' :: Text
domainName = Text
pDomainName_
    }

-- | The Amazon WorkMail organization for which the domain will be
-- deregistered.
deregisterMailDomain_organizationId :: Lens.Lens' DeregisterMailDomain Prelude.Text
deregisterMailDomain_organizationId :: (Text -> f Text) -> DeregisterMailDomain -> f DeregisterMailDomain
deregisterMailDomain_organizationId = (DeregisterMailDomain -> Text)
-> (DeregisterMailDomain -> Text -> DeregisterMailDomain)
-> Lens DeregisterMailDomain DeregisterMailDomain Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeregisterMailDomain' {Text
organizationId :: Text
$sel:organizationId:DeregisterMailDomain' :: DeregisterMailDomain -> Text
organizationId} -> Text
organizationId) (\s :: DeregisterMailDomain
s@DeregisterMailDomain' {} Text
a -> DeregisterMailDomain
s {$sel:organizationId:DeregisterMailDomain' :: Text
organizationId = Text
a} :: DeregisterMailDomain)

-- | The domain to deregister in WorkMail and SES.
deregisterMailDomain_domainName :: Lens.Lens' DeregisterMailDomain Prelude.Text
deregisterMailDomain_domainName :: (Text -> f Text) -> DeregisterMailDomain -> f DeregisterMailDomain
deregisterMailDomain_domainName = (DeregisterMailDomain -> Text)
-> (DeregisterMailDomain -> Text -> DeregisterMailDomain)
-> Lens DeregisterMailDomain DeregisterMailDomain Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeregisterMailDomain' {Text
domainName :: Text
$sel:domainName:DeregisterMailDomain' :: DeregisterMailDomain -> Text
domainName} -> Text
domainName) (\s :: DeregisterMailDomain
s@DeregisterMailDomain' {} Text
a -> DeregisterMailDomain
s {$sel:domainName:DeregisterMailDomain' :: Text
domainName = Text
a} :: DeregisterMailDomain)

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

instance Prelude.NFData DeregisterMailDomain

instance Core.ToHeaders DeregisterMailDomain where
  toHeaders :: DeregisterMailDomain -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeregisterMailDomain -> 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.DeregisterMailDomain" ::
                          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 DeregisterMailDomain where
  toJSON :: DeregisterMailDomain -> Value
toJSON DeregisterMailDomain' {Text
domainName :: Text
organizationId :: Text
$sel:domainName:DeregisterMailDomain' :: DeregisterMailDomain -> Text
$sel:organizationId:DeregisterMailDomain' :: DeregisterMailDomain -> 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
"DomainName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
domainName)
          ]
      )

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

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

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

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

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

instance Prelude.NFData DeregisterMailDomainResponse