{-# 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.CloudHSM.CreateHapg
-- 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)
--
-- This is documentation for __AWS CloudHSM Classic__. For more
-- information, see
-- <http://aws.amazon.com/cloudhsm/faqs-classic/ AWS CloudHSM Classic FAQs>,
-- the
-- <https://docs.aws.amazon.com/cloudhsm/classic/userguide/ AWS CloudHSM Classic User Guide>,
-- and the
-- <https://docs.aws.amazon.com/cloudhsm/classic/APIReference/ AWS CloudHSM Classic API Reference>.
--
-- __For information about the current version of AWS CloudHSM__, see
-- <http://aws.amazon.com/cloudhsm/ AWS CloudHSM>, the
-- <https://docs.aws.amazon.com/cloudhsm/latest/userguide/ AWS CloudHSM User Guide>,
-- and the
-- <https://docs.aws.amazon.com/cloudhsm/latest/APIReference/ AWS CloudHSM API Reference>.
--
-- Creates a high-availability partition group. A high-availability
-- partition group is a group of partitions that spans multiple physical
-- HSMs.
module Amazonka.CloudHSM.CreateHapg
  ( -- * Creating a Request
    CreateHapg (..),
    newCreateHapg,

    -- * Request Lenses
    createHapg_label,

    -- * Destructuring the Response
    CreateHapgResponse (..),
    newCreateHapgResponse,

    -- * Response Lenses
    createHapgResponse_hapgArn,
    createHapgResponse_httpStatus,
  )
where

import Amazonka.CloudHSM.Types
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

-- | Contains the inputs for the CreateHapgRequest action.
--
-- /See:/ 'newCreateHapg' smart constructor.
data CreateHapg = CreateHapg'
  { -- | The label of the new high-availability partition group.
    CreateHapg -> Text
label :: Prelude.Text
  }
  deriving (CreateHapg -> CreateHapg -> Bool
(CreateHapg -> CreateHapg -> Bool)
-> (CreateHapg -> CreateHapg -> Bool) -> Eq CreateHapg
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateHapg -> CreateHapg -> Bool
$c/= :: CreateHapg -> CreateHapg -> Bool
== :: CreateHapg -> CreateHapg -> Bool
$c== :: CreateHapg -> CreateHapg -> Bool
Prelude.Eq, ReadPrec [CreateHapg]
ReadPrec CreateHapg
Int -> ReadS CreateHapg
ReadS [CreateHapg]
(Int -> ReadS CreateHapg)
-> ReadS [CreateHapg]
-> ReadPrec CreateHapg
-> ReadPrec [CreateHapg]
-> Read CreateHapg
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateHapg]
$creadListPrec :: ReadPrec [CreateHapg]
readPrec :: ReadPrec CreateHapg
$creadPrec :: ReadPrec CreateHapg
readList :: ReadS [CreateHapg]
$creadList :: ReadS [CreateHapg]
readsPrec :: Int -> ReadS CreateHapg
$creadsPrec :: Int -> ReadS CreateHapg
Prelude.Read, Int -> CreateHapg -> ShowS
[CreateHapg] -> ShowS
CreateHapg -> String
(Int -> CreateHapg -> ShowS)
-> (CreateHapg -> String)
-> ([CreateHapg] -> ShowS)
-> Show CreateHapg
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateHapg] -> ShowS
$cshowList :: [CreateHapg] -> ShowS
show :: CreateHapg -> String
$cshow :: CreateHapg -> String
showsPrec :: Int -> CreateHapg -> ShowS
$cshowsPrec :: Int -> CreateHapg -> ShowS
Prelude.Show, (forall x. CreateHapg -> Rep CreateHapg x)
-> (forall x. Rep CreateHapg x -> CreateHapg) -> Generic CreateHapg
forall x. Rep CreateHapg x -> CreateHapg
forall x. CreateHapg -> Rep CreateHapg x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateHapg x -> CreateHapg
$cfrom :: forall x. CreateHapg -> Rep CreateHapg x
Prelude.Generic)

-- |
-- Create a value of 'CreateHapg' 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:
--
-- 'label', 'createHapg_label' - The label of the new high-availability partition group.
newCreateHapg ::
  -- | 'label'
  Prelude.Text ->
  CreateHapg
newCreateHapg :: Text -> CreateHapg
newCreateHapg Text
pLabel_ = CreateHapg' :: Text -> CreateHapg
CreateHapg' {$sel:label:CreateHapg' :: Text
label = Text
pLabel_}

-- | The label of the new high-availability partition group.
createHapg_label :: Lens.Lens' CreateHapg Prelude.Text
createHapg_label :: (Text -> f Text) -> CreateHapg -> f CreateHapg
createHapg_label = (CreateHapg -> Text)
-> (CreateHapg -> Text -> CreateHapg)
-> Lens CreateHapg CreateHapg Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateHapg' {Text
label :: Text
$sel:label:CreateHapg' :: CreateHapg -> Text
label} -> Text
label) (\s :: CreateHapg
s@CreateHapg' {} Text
a -> CreateHapg
s {$sel:label:CreateHapg' :: Text
label = Text
a} :: CreateHapg)

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

instance Prelude.NFData CreateHapg

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

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

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

-- | Contains the output of the CreateHAPartitionGroup action.
--
-- /See:/ 'newCreateHapgResponse' smart constructor.
data CreateHapgResponse = CreateHapgResponse'
  { -- | The ARN of the high-availability partition group.
    CreateHapgResponse -> Maybe Text
hapgArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreateHapgResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateHapgResponse -> CreateHapgResponse -> Bool
(CreateHapgResponse -> CreateHapgResponse -> Bool)
-> (CreateHapgResponse -> CreateHapgResponse -> Bool)
-> Eq CreateHapgResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateHapgResponse -> CreateHapgResponse -> Bool
$c/= :: CreateHapgResponse -> CreateHapgResponse -> Bool
== :: CreateHapgResponse -> CreateHapgResponse -> Bool
$c== :: CreateHapgResponse -> CreateHapgResponse -> Bool
Prelude.Eq, ReadPrec [CreateHapgResponse]
ReadPrec CreateHapgResponse
Int -> ReadS CreateHapgResponse
ReadS [CreateHapgResponse]
(Int -> ReadS CreateHapgResponse)
-> ReadS [CreateHapgResponse]
-> ReadPrec CreateHapgResponse
-> ReadPrec [CreateHapgResponse]
-> Read CreateHapgResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateHapgResponse]
$creadListPrec :: ReadPrec [CreateHapgResponse]
readPrec :: ReadPrec CreateHapgResponse
$creadPrec :: ReadPrec CreateHapgResponse
readList :: ReadS [CreateHapgResponse]
$creadList :: ReadS [CreateHapgResponse]
readsPrec :: Int -> ReadS CreateHapgResponse
$creadsPrec :: Int -> ReadS CreateHapgResponse
Prelude.Read, Int -> CreateHapgResponse -> ShowS
[CreateHapgResponse] -> ShowS
CreateHapgResponse -> String
(Int -> CreateHapgResponse -> ShowS)
-> (CreateHapgResponse -> String)
-> ([CreateHapgResponse] -> ShowS)
-> Show CreateHapgResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateHapgResponse] -> ShowS
$cshowList :: [CreateHapgResponse] -> ShowS
show :: CreateHapgResponse -> String
$cshow :: CreateHapgResponse -> String
showsPrec :: Int -> CreateHapgResponse -> ShowS
$cshowsPrec :: Int -> CreateHapgResponse -> ShowS
Prelude.Show, (forall x. CreateHapgResponse -> Rep CreateHapgResponse x)
-> (forall x. Rep CreateHapgResponse x -> CreateHapgResponse)
-> Generic CreateHapgResponse
forall x. Rep CreateHapgResponse x -> CreateHapgResponse
forall x. CreateHapgResponse -> Rep CreateHapgResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateHapgResponse x -> CreateHapgResponse
$cfrom :: forall x. CreateHapgResponse -> Rep CreateHapgResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateHapgResponse' 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:
--
-- 'hapgArn', 'createHapgResponse_hapgArn' - The ARN of the high-availability partition group.
--
-- 'httpStatus', 'createHapgResponse_httpStatus' - The response's http status code.
newCreateHapgResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateHapgResponse
newCreateHapgResponse :: Int -> CreateHapgResponse
newCreateHapgResponse Int
pHttpStatus_ =
  CreateHapgResponse' :: Maybe Text -> Int -> CreateHapgResponse
CreateHapgResponse'
    { $sel:hapgArn:CreateHapgResponse' :: Maybe Text
hapgArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateHapgResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the high-availability partition group.
createHapgResponse_hapgArn :: Lens.Lens' CreateHapgResponse (Prelude.Maybe Prelude.Text)
createHapgResponse_hapgArn :: (Maybe Text -> f (Maybe Text))
-> CreateHapgResponse -> f CreateHapgResponse
createHapgResponse_hapgArn = (CreateHapgResponse -> Maybe Text)
-> (CreateHapgResponse -> Maybe Text -> CreateHapgResponse)
-> Lens
     CreateHapgResponse CreateHapgResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateHapgResponse' {Maybe Text
hapgArn :: Maybe Text
$sel:hapgArn:CreateHapgResponse' :: CreateHapgResponse -> Maybe Text
hapgArn} -> Maybe Text
hapgArn) (\s :: CreateHapgResponse
s@CreateHapgResponse' {} Maybe Text
a -> CreateHapgResponse
s {$sel:hapgArn:CreateHapgResponse' :: Maybe Text
hapgArn = Maybe Text
a} :: CreateHapgResponse)

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

instance Prelude.NFData CreateHapgResponse