{-# 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.Organizations.DeclineHandshake
-- 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)
--
-- Declines a handshake request. This sets the handshake state to
-- @DECLINED@ and effectively deactivates the request.
--
-- This operation can be called only from the account that received the
-- handshake. The originator of the handshake can use CancelHandshake
-- instead. The originator can\'t reactivate a declined request, but can
-- reinitiate the process with a new handshake request.
--
-- After you decline a handshake, it continues to appear in the results of
-- relevant APIs for only 30 days. After that, it\'s deleted.
module Amazonka.Organizations.DeclineHandshake
  ( -- * Creating a Request
    DeclineHandshake (..),
    newDeclineHandshake,

    -- * Request Lenses
    declineHandshake_handshakeId,

    -- * Destructuring the Response
    DeclineHandshakeResponse (..),
    newDeclineHandshakeResponse,

    -- * Response Lenses
    declineHandshakeResponse_handshake,
    declineHandshakeResponse_httpStatus,
  )
where

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

-- | /See:/ 'newDeclineHandshake' smart constructor.
data DeclineHandshake = DeclineHandshake'
  { -- | The unique identifier (ID) of the handshake that you want to decline.
    -- You can get the ID from the ListHandshakesForAccount operation.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for handshake ID
    -- string requires \"h-\" followed by from 8 to 32 lowercase letters or
    -- digits.
    DeclineHandshake -> Text
handshakeId :: Prelude.Text
  }
  deriving (DeclineHandshake -> DeclineHandshake -> Bool
(DeclineHandshake -> DeclineHandshake -> Bool)
-> (DeclineHandshake -> DeclineHandshake -> Bool)
-> Eq DeclineHandshake
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeclineHandshake -> DeclineHandshake -> Bool
$c/= :: DeclineHandshake -> DeclineHandshake -> Bool
== :: DeclineHandshake -> DeclineHandshake -> Bool
$c== :: DeclineHandshake -> DeclineHandshake -> Bool
Prelude.Eq, ReadPrec [DeclineHandshake]
ReadPrec DeclineHandshake
Int -> ReadS DeclineHandshake
ReadS [DeclineHandshake]
(Int -> ReadS DeclineHandshake)
-> ReadS [DeclineHandshake]
-> ReadPrec DeclineHandshake
-> ReadPrec [DeclineHandshake]
-> Read DeclineHandshake
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeclineHandshake]
$creadListPrec :: ReadPrec [DeclineHandshake]
readPrec :: ReadPrec DeclineHandshake
$creadPrec :: ReadPrec DeclineHandshake
readList :: ReadS [DeclineHandshake]
$creadList :: ReadS [DeclineHandshake]
readsPrec :: Int -> ReadS DeclineHandshake
$creadsPrec :: Int -> ReadS DeclineHandshake
Prelude.Read, Int -> DeclineHandshake -> ShowS
[DeclineHandshake] -> ShowS
DeclineHandshake -> String
(Int -> DeclineHandshake -> ShowS)
-> (DeclineHandshake -> String)
-> ([DeclineHandshake] -> ShowS)
-> Show DeclineHandshake
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeclineHandshake] -> ShowS
$cshowList :: [DeclineHandshake] -> ShowS
show :: DeclineHandshake -> String
$cshow :: DeclineHandshake -> String
showsPrec :: Int -> DeclineHandshake -> ShowS
$cshowsPrec :: Int -> DeclineHandshake -> ShowS
Prelude.Show, (forall x. DeclineHandshake -> Rep DeclineHandshake x)
-> (forall x. Rep DeclineHandshake x -> DeclineHandshake)
-> Generic DeclineHandshake
forall x. Rep DeclineHandshake x -> DeclineHandshake
forall x. DeclineHandshake -> Rep DeclineHandshake x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeclineHandshake x -> DeclineHandshake
$cfrom :: forall x. DeclineHandshake -> Rep DeclineHandshake x
Prelude.Generic)

-- |
-- Create a value of 'DeclineHandshake' 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:
--
-- 'handshakeId', 'declineHandshake_handshakeId' - The unique identifier (ID) of the handshake that you want to decline.
-- You can get the ID from the ListHandshakesForAccount operation.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for handshake ID
-- string requires \"h-\" followed by from 8 to 32 lowercase letters or
-- digits.
newDeclineHandshake ::
  -- | 'handshakeId'
  Prelude.Text ->
  DeclineHandshake
newDeclineHandshake :: Text -> DeclineHandshake
newDeclineHandshake Text
pHandshakeId_ =
  DeclineHandshake' :: Text -> DeclineHandshake
DeclineHandshake' {$sel:handshakeId:DeclineHandshake' :: Text
handshakeId = Text
pHandshakeId_}

-- | The unique identifier (ID) of the handshake that you want to decline.
-- You can get the ID from the ListHandshakesForAccount operation.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for handshake ID
-- string requires \"h-\" followed by from 8 to 32 lowercase letters or
-- digits.
declineHandshake_handshakeId :: Lens.Lens' DeclineHandshake Prelude.Text
declineHandshake_handshakeId :: (Text -> f Text) -> DeclineHandshake -> f DeclineHandshake
declineHandshake_handshakeId = (DeclineHandshake -> Text)
-> (DeclineHandshake -> Text -> DeclineHandshake)
-> Lens DeclineHandshake DeclineHandshake Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeclineHandshake' {Text
handshakeId :: Text
$sel:handshakeId:DeclineHandshake' :: DeclineHandshake -> Text
handshakeId} -> Text
handshakeId) (\s :: DeclineHandshake
s@DeclineHandshake' {} Text
a -> DeclineHandshake
s {$sel:handshakeId:DeclineHandshake' :: Text
handshakeId = Text
a} :: DeclineHandshake)

instance Core.AWSRequest DeclineHandshake where
  type
    AWSResponse DeclineHandshake =
      DeclineHandshakeResponse
  request :: DeclineHandshake -> Request DeclineHandshake
request = Service -> DeclineHandshake -> Request DeclineHandshake
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeclineHandshake
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeclineHandshake)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DeclineHandshake))
-> Logger
-> Service
-> Proxy DeclineHandshake
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeclineHandshake)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Handshake -> Int -> DeclineHandshakeResponse
DeclineHandshakeResponse'
            (Maybe Handshake -> Int -> DeclineHandshakeResponse)
-> Either String (Maybe Handshake)
-> Either String (Int -> DeclineHandshakeResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Handshake)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Handshake")
            Either String (Int -> DeclineHandshakeResponse)
-> Either String Int -> Either String DeclineHandshakeResponse
forall (f :: * -> *) a b. Applicative f => 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 DeclineHandshake

instance Prelude.NFData DeclineHandshake

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

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

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

-- | /See:/ 'newDeclineHandshakeResponse' smart constructor.
data DeclineHandshakeResponse = DeclineHandshakeResponse'
  { -- | A structure that contains details about the declined handshake. The
    -- state is updated to show the value @DECLINED@.
    DeclineHandshakeResponse -> Maybe Handshake
handshake :: Prelude.Maybe Handshake,
    -- | The response's http status code.
    DeclineHandshakeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeclineHandshakeResponse -> DeclineHandshakeResponse -> Bool
(DeclineHandshakeResponse -> DeclineHandshakeResponse -> Bool)
-> (DeclineHandshakeResponse -> DeclineHandshakeResponse -> Bool)
-> Eq DeclineHandshakeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeclineHandshakeResponse -> DeclineHandshakeResponse -> Bool
$c/= :: DeclineHandshakeResponse -> DeclineHandshakeResponse -> Bool
== :: DeclineHandshakeResponse -> DeclineHandshakeResponse -> Bool
$c== :: DeclineHandshakeResponse -> DeclineHandshakeResponse -> Bool
Prelude.Eq, Int -> DeclineHandshakeResponse -> ShowS
[DeclineHandshakeResponse] -> ShowS
DeclineHandshakeResponse -> String
(Int -> DeclineHandshakeResponse -> ShowS)
-> (DeclineHandshakeResponse -> String)
-> ([DeclineHandshakeResponse] -> ShowS)
-> Show DeclineHandshakeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeclineHandshakeResponse] -> ShowS
$cshowList :: [DeclineHandshakeResponse] -> ShowS
show :: DeclineHandshakeResponse -> String
$cshow :: DeclineHandshakeResponse -> String
showsPrec :: Int -> DeclineHandshakeResponse -> ShowS
$cshowsPrec :: Int -> DeclineHandshakeResponse -> ShowS
Prelude.Show, (forall x.
 DeclineHandshakeResponse -> Rep DeclineHandshakeResponse x)
-> (forall x.
    Rep DeclineHandshakeResponse x -> DeclineHandshakeResponse)
-> Generic DeclineHandshakeResponse
forall x.
Rep DeclineHandshakeResponse x -> DeclineHandshakeResponse
forall x.
DeclineHandshakeResponse -> Rep DeclineHandshakeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DeclineHandshakeResponse x -> DeclineHandshakeResponse
$cfrom :: forall x.
DeclineHandshakeResponse -> Rep DeclineHandshakeResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeclineHandshakeResponse' 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:
--
-- 'handshake', 'declineHandshakeResponse_handshake' - A structure that contains details about the declined handshake. The
-- state is updated to show the value @DECLINED@.
--
-- 'httpStatus', 'declineHandshakeResponse_httpStatus' - The response's http status code.
newDeclineHandshakeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeclineHandshakeResponse
newDeclineHandshakeResponse :: Int -> DeclineHandshakeResponse
newDeclineHandshakeResponse Int
pHttpStatus_ =
  DeclineHandshakeResponse' :: Maybe Handshake -> Int -> DeclineHandshakeResponse
DeclineHandshakeResponse'
    { $sel:handshake:DeclineHandshakeResponse' :: Maybe Handshake
handshake =
        Maybe Handshake
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeclineHandshakeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that contains details about the declined handshake. The
-- state is updated to show the value @DECLINED@.
declineHandshakeResponse_handshake :: Lens.Lens' DeclineHandshakeResponse (Prelude.Maybe Handshake)
declineHandshakeResponse_handshake :: (Maybe Handshake -> f (Maybe Handshake))
-> DeclineHandshakeResponse -> f DeclineHandshakeResponse
declineHandshakeResponse_handshake = (DeclineHandshakeResponse -> Maybe Handshake)
-> (DeclineHandshakeResponse
    -> Maybe Handshake -> DeclineHandshakeResponse)
-> Lens
     DeclineHandshakeResponse
     DeclineHandshakeResponse
     (Maybe Handshake)
     (Maybe Handshake)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeclineHandshakeResponse' {Maybe Handshake
handshake :: Maybe Handshake
$sel:handshake:DeclineHandshakeResponse' :: DeclineHandshakeResponse -> Maybe Handshake
handshake} -> Maybe Handshake
handshake) (\s :: DeclineHandshakeResponse
s@DeclineHandshakeResponse' {} Maybe Handshake
a -> DeclineHandshakeResponse
s {$sel:handshake:DeclineHandshakeResponse' :: Maybe Handshake
handshake = Maybe Handshake
a} :: DeclineHandshakeResponse)

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

instance Prelude.NFData DeclineHandshakeResponse