{-# 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.DescribeHandshake
-- 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)
--
-- Retrieves information about a previously requested handshake. The
-- handshake ID comes from the response to the original
-- InviteAccountToOrganization operation that generated the handshake.
--
-- You can access handshakes that are @ACCEPTED@, @DECLINED@, or @CANCELED@
-- for only 30 days after they change to that state. They\'re then deleted
-- and no longer accessible.
--
-- This operation can be called from any account in the organization.
module Amazonka.Organizations.DescribeHandshake
  ( -- * Creating a Request
    DescribeHandshake (..),
    newDescribeHandshake,

    -- * Request Lenses
    describeHandshake_handshakeId,

    -- * Destructuring the Response
    DescribeHandshakeResponse (..),
    newDescribeHandshakeResponse,

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

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

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

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

instance Prelude.NFData DescribeHandshake

instance Core.ToHeaders DescribeHandshake where
  toHeaders :: DescribeHandshake -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeHandshake -> 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.DescribeHandshake" ::
                          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 DescribeHandshake where
  toJSON :: DescribeHandshake -> Value
toJSON DescribeHandshake' {Text
handshakeId :: Text
$sel:handshakeId:DescribeHandshake' :: DescribeHandshake -> 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 DescribeHandshake where
  toPath :: DescribeHandshake -> ByteString
toPath = ByteString -> DescribeHandshake -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newDescribeHandshakeResponse' smart constructor.
data DescribeHandshakeResponse = DescribeHandshakeResponse'
  { -- | A structure that contains information about the specified handshake.
    DescribeHandshakeResponse -> Maybe Handshake
handshake :: Prelude.Maybe Handshake,
    -- | The response's http status code.
    DescribeHandshakeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeHandshakeResponse -> DescribeHandshakeResponse -> Bool
(DescribeHandshakeResponse -> DescribeHandshakeResponse -> Bool)
-> (DescribeHandshakeResponse -> DescribeHandshakeResponse -> Bool)
-> Eq DescribeHandshakeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeHandshakeResponse -> DescribeHandshakeResponse -> Bool
$c/= :: DescribeHandshakeResponse -> DescribeHandshakeResponse -> Bool
== :: DescribeHandshakeResponse -> DescribeHandshakeResponse -> Bool
$c== :: DescribeHandshakeResponse -> DescribeHandshakeResponse -> Bool
Prelude.Eq, Int -> DescribeHandshakeResponse -> ShowS
[DescribeHandshakeResponse] -> ShowS
DescribeHandshakeResponse -> String
(Int -> DescribeHandshakeResponse -> ShowS)
-> (DescribeHandshakeResponse -> String)
-> ([DescribeHandshakeResponse] -> ShowS)
-> Show DescribeHandshakeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeHandshakeResponse] -> ShowS
$cshowList :: [DescribeHandshakeResponse] -> ShowS
show :: DescribeHandshakeResponse -> String
$cshow :: DescribeHandshakeResponse -> String
showsPrec :: Int -> DescribeHandshakeResponse -> ShowS
$cshowsPrec :: Int -> DescribeHandshakeResponse -> ShowS
Prelude.Show, (forall x.
 DescribeHandshakeResponse -> Rep DescribeHandshakeResponse x)
-> (forall x.
    Rep DescribeHandshakeResponse x -> DescribeHandshakeResponse)
-> Generic DescribeHandshakeResponse
forall x.
Rep DescribeHandshakeResponse x -> DescribeHandshakeResponse
forall x.
DescribeHandshakeResponse -> Rep DescribeHandshakeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeHandshakeResponse x -> DescribeHandshakeResponse
$cfrom :: forall x.
DescribeHandshakeResponse -> Rep DescribeHandshakeResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeHandshakeResponse' 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', 'describeHandshakeResponse_handshake' - A structure that contains information about the specified handshake.
--
-- 'httpStatus', 'describeHandshakeResponse_httpStatus' - The response's http status code.
newDescribeHandshakeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeHandshakeResponse
newDescribeHandshakeResponse :: Int -> DescribeHandshakeResponse
newDescribeHandshakeResponse Int
pHttpStatus_ =
  DescribeHandshakeResponse' :: Maybe Handshake -> Int -> DescribeHandshakeResponse
DescribeHandshakeResponse'
    { $sel:handshake:DescribeHandshakeResponse' :: Maybe Handshake
handshake =
        Maybe Handshake
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeHandshakeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that contains information about the specified handshake.
describeHandshakeResponse_handshake :: Lens.Lens' DescribeHandshakeResponse (Prelude.Maybe Handshake)
describeHandshakeResponse_handshake :: (Maybe Handshake -> f (Maybe Handshake))
-> DescribeHandshakeResponse -> f DescribeHandshakeResponse
describeHandshakeResponse_handshake = (DescribeHandshakeResponse -> Maybe Handshake)
-> (DescribeHandshakeResponse
    -> Maybe Handshake -> DescribeHandshakeResponse)
-> Lens
     DescribeHandshakeResponse
     DescribeHandshakeResponse
     (Maybe Handshake)
     (Maybe Handshake)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeHandshakeResponse' {Maybe Handshake
handshake :: Maybe Handshake
$sel:handshake:DescribeHandshakeResponse' :: DescribeHandshakeResponse -> Maybe Handshake
handshake} -> Maybe Handshake
handshake) (\s :: DescribeHandshakeResponse
s@DescribeHandshakeResponse' {} Maybe Handshake
a -> DescribeHandshakeResponse
s {$sel:handshake:DescribeHandshakeResponse' :: Maybe Handshake
handshake = Maybe Handshake
a} :: DescribeHandshakeResponse)

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

instance Prelude.NFData DescribeHandshakeResponse