{-# 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.GetRegistrationCode
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets a registration code used to register a CA certificate with IoT.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions GetRegistrationCode>
-- action.
module Amazonka.IoT.GetRegistrationCode
  ( -- * Creating a Request
    GetRegistrationCode (..),
    newGetRegistrationCode,

    -- * Destructuring the Response
    GetRegistrationCodeResponse (..),
    newGetRegistrationCodeResponse,

    -- * Response Lenses
    getRegistrationCodeResponse_registrationCode,
    getRegistrationCodeResponse_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 to the GetRegistrationCode operation.
--
-- /See:/ 'newGetRegistrationCode' smart constructor.
data GetRegistrationCode = GetRegistrationCode'
  {
  }
  deriving (GetRegistrationCode -> GetRegistrationCode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRegistrationCode -> GetRegistrationCode -> Bool
$c/= :: GetRegistrationCode -> GetRegistrationCode -> Bool
== :: GetRegistrationCode -> GetRegistrationCode -> Bool
$c== :: GetRegistrationCode -> GetRegistrationCode -> Bool
Prelude.Eq, ReadPrec [GetRegistrationCode]
ReadPrec GetRegistrationCode
Int -> ReadS GetRegistrationCode
ReadS [GetRegistrationCode]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRegistrationCode]
$creadListPrec :: ReadPrec [GetRegistrationCode]
readPrec :: ReadPrec GetRegistrationCode
$creadPrec :: ReadPrec GetRegistrationCode
readList :: ReadS [GetRegistrationCode]
$creadList :: ReadS [GetRegistrationCode]
readsPrec :: Int -> ReadS GetRegistrationCode
$creadsPrec :: Int -> ReadS GetRegistrationCode
Prelude.Read, Int -> GetRegistrationCode -> ShowS
[GetRegistrationCode] -> ShowS
GetRegistrationCode -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRegistrationCode] -> ShowS
$cshowList :: [GetRegistrationCode] -> ShowS
show :: GetRegistrationCode -> String
$cshow :: GetRegistrationCode -> String
showsPrec :: Int -> GetRegistrationCode -> ShowS
$cshowsPrec :: Int -> GetRegistrationCode -> ShowS
Prelude.Show, forall x. Rep GetRegistrationCode x -> GetRegistrationCode
forall x. GetRegistrationCode -> Rep GetRegistrationCode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRegistrationCode x -> GetRegistrationCode
$cfrom :: forall x. GetRegistrationCode -> Rep GetRegistrationCode x
Prelude.Generic)

-- |
-- Create a value of 'GetRegistrationCode' 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.
newGetRegistrationCode ::
  GetRegistrationCode
newGetRegistrationCode :: GetRegistrationCode
newGetRegistrationCode = GetRegistrationCode
GetRegistrationCode'

instance Core.AWSRequest GetRegistrationCode where
  type
    AWSResponse GetRegistrationCode =
      GetRegistrationCodeResponse
  request :: (Service -> Service)
-> GetRegistrationCode -> Request GetRegistrationCode
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetRegistrationCode
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetRegistrationCode)))
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 -> GetRegistrationCodeResponse
GetRegistrationCodeResponse'
            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
"registrationCode")
            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 GetRegistrationCode where
  hashWithSalt :: Int -> GetRegistrationCode -> Int
hashWithSalt Int
_salt GetRegistrationCode
_ =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ()

instance Prelude.NFData GetRegistrationCode where
  rnf :: GetRegistrationCode -> ()
rnf GetRegistrationCode
_ = ()

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

instance Data.ToPath GetRegistrationCode where
  toPath :: GetRegistrationCode -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/registrationcode"

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

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

-- |
-- Create a value of 'GetRegistrationCodeResponse' 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:
--
-- 'registrationCode', 'getRegistrationCodeResponse_registrationCode' - The CA certificate registration code.
--
-- 'httpStatus', 'getRegistrationCodeResponse_httpStatus' - The response's http status code.
newGetRegistrationCodeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetRegistrationCodeResponse
newGetRegistrationCodeResponse :: Int -> GetRegistrationCodeResponse
newGetRegistrationCodeResponse Int
pHttpStatus_ =
  GetRegistrationCodeResponse'
    { $sel:registrationCode:GetRegistrationCodeResponse' :: Maybe Text
registrationCode =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetRegistrationCodeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The CA certificate registration code.
getRegistrationCodeResponse_registrationCode :: Lens.Lens' GetRegistrationCodeResponse (Prelude.Maybe Prelude.Text)
getRegistrationCodeResponse_registrationCode :: Lens' GetRegistrationCodeResponse (Maybe Text)
getRegistrationCodeResponse_registrationCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRegistrationCodeResponse' {Maybe Text
registrationCode :: Maybe Text
$sel:registrationCode:GetRegistrationCodeResponse' :: GetRegistrationCodeResponse -> Maybe Text
registrationCode} -> Maybe Text
registrationCode) (\s :: GetRegistrationCodeResponse
s@GetRegistrationCodeResponse' {} Maybe Text
a -> GetRegistrationCodeResponse
s {$sel:registrationCode:GetRegistrationCodeResponse' :: Maybe Text
registrationCode = Maybe Text
a} :: GetRegistrationCodeResponse)

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

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