{-# 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.IoT.TransferCertificate
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Transfers the specified certificate to the specified Amazon Web Services
-- account.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions TransferCertificate>
-- action.
--
-- You can cancel the transfer until it is acknowledged by the recipient.
--
-- No notification is sent to the transfer destination\'s account. It is up
-- to the caller to notify the transfer target.
--
-- The certificate being transferred must not be in the ACTIVE state. You
-- can use the UpdateCertificate action to deactivate it.
--
-- The certificate must not have any policies attached to it. You can use
-- the DetachPolicy action to detach them.
module Amazonka.IoT.TransferCertificate
  ( -- * Creating a Request
    TransferCertificate (..),
    newTransferCertificate,

    -- * Request Lenses
    transferCertificate_transferMessage,
    transferCertificate_certificateId,
    transferCertificate_targetAwsAccount,

    -- * Destructuring the Response
    TransferCertificateResponse (..),
    newTransferCertificateResponse,

    -- * Response Lenses
    transferCertificateResponse_transferredCertificateArn,
    transferCertificateResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | The input for the TransferCertificate operation.
--
-- /See:/ 'newTransferCertificate' smart constructor.
data TransferCertificate = TransferCertificate'
  { -- | The transfer message.
    TransferCertificate -> Maybe Text
transferMessage :: Prelude.Maybe Prelude.Text,
    -- | The ID of the certificate. (The last part of the certificate ARN
    -- contains the certificate ID.)
    TransferCertificate -> Text
certificateId :: Prelude.Text,
    -- | The Amazon Web Services account.
    TransferCertificate -> Text
targetAwsAccount :: Prelude.Text
  }
  deriving (TransferCertificate -> TransferCertificate -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TransferCertificate -> TransferCertificate -> Bool
$c/= :: TransferCertificate -> TransferCertificate -> Bool
== :: TransferCertificate -> TransferCertificate -> Bool
$c== :: TransferCertificate -> TransferCertificate -> Bool
Prelude.Eq, ReadPrec [TransferCertificate]
ReadPrec TransferCertificate
Int -> ReadS TransferCertificate
ReadS [TransferCertificate]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TransferCertificate]
$creadListPrec :: ReadPrec [TransferCertificate]
readPrec :: ReadPrec TransferCertificate
$creadPrec :: ReadPrec TransferCertificate
readList :: ReadS [TransferCertificate]
$creadList :: ReadS [TransferCertificate]
readsPrec :: Int -> ReadS TransferCertificate
$creadsPrec :: Int -> ReadS TransferCertificate
Prelude.Read, Int -> TransferCertificate -> ShowS
[TransferCertificate] -> ShowS
TransferCertificate -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TransferCertificate] -> ShowS
$cshowList :: [TransferCertificate] -> ShowS
show :: TransferCertificate -> String
$cshow :: TransferCertificate -> String
showsPrec :: Int -> TransferCertificate -> ShowS
$cshowsPrec :: Int -> TransferCertificate -> ShowS
Prelude.Show, forall x. Rep TransferCertificate x -> TransferCertificate
forall x. TransferCertificate -> Rep TransferCertificate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TransferCertificate x -> TransferCertificate
$cfrom :: forall x. TransferCertificate -> Rep TransferCertificate x
Prelude.Generic)

-- |
-- Create a value of 'TransferCertificate' 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:
--
-- 'transferMessage', 'transferCertificate_transferMessage' - The transfer message.
--
-- 'certificateId', 'transferCertificate_certificateId' - The ID of the certificate. (The last part of the certificate ARN
-- contains the certificate ID.)
--
-- 'targetAwsAccount', 'transferCertificate_targetAwsAccount' - The Amazon Web Services account.
newTransferCertificate ::
  -- | 'certificateId'
  Prelude.Text ->
  -- | 'targetAwsAccount'
  Prelude.Text ->
  TransferCertificate
newTransferCertificate :: Text -> Text -> TransferCertificate
newTransferCertificate
  Text
pCertificateId_
  Text
pTargetAwsAccount_ =
    TransferCertificate'
      { $sel:transferMessage:TransferCertificate' :: Maybe Text
transferMessage =
          forall a. Maybe a
Prelude.Nothing,
        $sel:certificateId:TransferCertificate' :: Text
certificateId = Text
pCertificateId_,
        $sel:targetAwsAccount:TransferCertificate' :: Text
targetAwsAccount = Text
pTargetAwsAccount_
      }

-- | The transfer message.
transferCertificate_transferMessage :: Lens.Lens' TransferCertificate (Prelude.Maybe Prelude.Text)
transferCertificate_transferMessage :: Lens' TransferCertificate (Maybe Text)
transferCertificate_transferMessage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransferCertificate' {Maybe Text
transferMessage :: Maybe Text
$sel:transferMessage:TransferCertificate' :: TransferCertificate -> Maybe Text
transferMessage} -> Maybe Text
transferMessage) (\s :: TransferCertificate
s@TransferCertificate' {} Maybe Text
a -> TransferCertificate
s {$sel:transferMessage:TransferCertificate' :: Maybe Text
transferMessage = Maybe Text
a} :: TransferCertificate)

-- | The ID of the certificate. (The last part of the certificate ARN
-- contains the certificate ID.)
transferCertificate_certificateId :: Lens.Lens' TransferCertificate Prelude.Text
transferCertificate_certificateId :: Lens' TransferCertificate Text
transferCertificate_certificateId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransferCertificate' {Text
certificateId :: Text
$sel:certificateId:TransferCertificate' :: TransferCertificate -> Text
certificateId} -> Text
certificateId) (\s :: TransferCertificate
s@TransferCertificate' {} Text
a -> TransferCertificate
s {$sel:certificateId:TransferCertificate' :: Text
certificateId = Text
a} :: TransferCertificate)

-- | The Amazon Web Services account.
transferCertificate_targetAwsAccount :: Lens.Lens' TransferCertificate Prelude.Text
transferCertificate_targetAwsAccount :: Lens' TransferCertificate Text
transferCertificate_targetAwsAccount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransferCertificate' {Text
targetAwsAccount :: Text
$sel:targetAwsAccount:TransferCertificate' :: TransferCertificate -> Text
targetAwsAccount} -> Text
targetAwsAccount) (\s :: TransferCertificate
s@TransferCertificate' {} Text
a -> TransferCertificate
s {$sel:targetAwsAccount:TransferCertificate' :: Text
targetAwsAccount = Text
a} :: TransferCertificate)

instance Core.AWSRequest TransferCertificate where
  type
    AWSResponse TransferCertificate =
      TransferCertificateResponse
  request :: (Service -> Service)
-> TransferCertificate -> Request TransferCertificate
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy TransferCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TransferCertificate)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> TransferCertificateResponse
TransferCertificateResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"transferredCertificateArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable TransferCertificate where
  hashWithSalt :: Int -> TransferCertificate -> Int
hashWithSalt Int
_salt TransferCertificate' {Maybe Text
Text
targetAwsAccount :: Text
certificateId :: Text
transferMessage :: Maybe Text
$sel:targetAwsAccount:TransferCertificate' :: TransferCertificate -> Text
$sel:certificateId:TransferCertificate' :: TransferCertificate -> Text
$sel:transferMessage:TransferCertificate' :: TransferCertificate -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
transferMessage
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
certificateId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
targetAwsAccount

instance Prelude.NFData TransferCertificate where
  rnf :: TransferCertificate -> ()
rnf TransferCertificate' {Maybe Text
Text
targetAwsAccount :: Text
certificateId :: Text
transferMessage :: Maybe Text
$sel:targetAwsAccount:TransferCertificate' :: TransferCertificate -> Text
$sel:certificateId:TransferCertificate' :: TransferCertificate -> Text
$sel:transferMessage:TransferCertificate' :: TransferCertificate -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
transferMessage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
certificateId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
targetAwsAccount

instance Data.ToHeaders TransferCertificate where
  toHeaders :: TransferCertificate -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToJSON TransferCertificate where
  toJSON :: TransferCertificate -> Value
toJSON TransferCertificate' {Maybe Text
Text
targetAwsAccount :: Text
certificateId :: Text
transferMessage :: Maybe Text
$sel:targetAwsAccount:TransferCertificate' :: TransferCertificate -> Text
$sel:certificateId:TransferCertificate' :: TransferCertificate -> Text
$sel:transferMessage:TransferCertificate' :: TransferCertificate -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"transferMessage" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
transferMessage
          ]
      )

instance Data.ToPath TransferCertificate where
  toPath :: TransferCertificate -> ByteString
toPath TransferCertificate' {Maybe Text
Text
targetAwsAccount :: Text
certificateId :: Text
transferMessage :: Maybe Text
$sel:targetAwsAccount:TransferCertificate' :: TransferCertificate -> Text
$sel:certificateId:TransferCertificate' :: TransferCertificate -> Text
$sel:transferMessage:TransferCertificate' :: TransferCertificate -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/transfer-certificate/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
certificateId]

instance Data.ToQuery TransferCertificate where
  toQuery :: TransferCertificate -> QueryString
toQuery TransferCertificate' {Maybe Text
Text
targetAwsAccount :: Text
certificateId :: Text
transferMessage :: Maybe Text
$sel:targetAwsAccount:TransferCertificate' :: TransferCertificate -> Text
$sel:certificateId:TransferCertificate' :: TransferCertificate -> Text
$sel:transferMessage:TransferCertificate' :: TransferCertificate -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"targetAwsAccount" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
targetAwsAccount]

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

-- |
-- Create a value of 'TransferCertificateResponse' 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:
--
-- 'transferredCertificateArn', 'transferCertificateResponse_transferredCertificateArn' - The ARN of the certificate.
--
-- 'httpStatus', 'transferCertificateResponse_httpStatus' - The response's http status code.
newTransferCertificateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TransferCertificateResponse
newTransferCertificateResponse :: Int -> TransferCertificateResponse
newTransferCertificateResponse Int
pHttpStatus_ =
  TransferCertificateResponse'
    { $sel:transferredCertificateArn:TransferCertificateResponse' :: Maybe Text
transferredCertificateArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:TransferCertificateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the certificate.
transferCertificateResponse_transferredCertificateArn :: Lens.Lens' TransferCertificateResponse (Prelude.Maybe Prelude.Text)
transferCertificateResponse_transferredCertificateArn :: Lens' TransferCertificateResponse (Maybe Text)
transferCertificateResponse_transferredCertificateArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransferCertificateResponse' {Maybe Text
transferredCertificateArn :: Maybe Text
$sel:transferredCertificateArn:TransferCertificateResponse' :: TransferCertificateResponse -> Maybe Text
transferredCertificateArn} -> Maybe Text
transferredCertificateArn) (\s :: TransferCertificateResponse
s@TransferCertificateResponse' {} Maybe Text
a -> TransferCertificateResponse
s {$sel:transferredCertificateArn:TransferCertificateResponse' :: Maybe Text
transferredCertificateArn = Maybe Text
a} :: TransferCertificateResponse)

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

instance Prelude.NFData TransferCertificateResponse where
  rnf :: TransferCertificateResponse -> ()
rnf TransferCertificateResponse' {Int
Maybe Text
httpStatus :: Int
transferredCertificateArn :: Maybe Text
$sel:httpStatus:TransferCertificateResponse' :: TransferCertificateResponse -> Int
$sel:transferredCertificateArn:TransferCertificateResponse' :: TransferCertificateResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
transferredCertificateArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus