{-# 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.ManagedBlockChain.CreateMember
-- 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)
--
-- Creates a member within a Managed Blockchain network.
--
-- Applies only to Hyperledger Fabric.
module Amazonka.ManagedBlockChain.CreateMember
  ( -- * Creating a Request
    CreateMember (..),
    newCreateMember,

    -- * Request Lenses
    createMember_clientRequestToken,
    createMember_invitationId,
    createMember_networkId,
    createMember_memberConfiguration,

    -- * Destructuring the Response
    CreateMemberResponse (..),
    newCreateMemberResponse,

    -- * Response Lenses
    createMemberResponse_memberId,
    createMemberResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateMember' smart constructor.
data CreateMember = CreateMember'
  { -- | A unique, case-sensitive identifier that you provide to ensure the
    -- idempotency of the operation. An idempotent operation completes no more
    -- than one time. This identifier is required only if you make a service
    -- request directly using an HTTP client. It is generated automatically if
    -- you use an AWS SDK or the AWS CLI.
    CreateMember -> Text
clientRequestToken :: Prelude.Text,
    -- | The unique identifier of the invitation that is sent to the member to
    -- join the network.
    CreateMember -> Text
invitationId :: Prelude.Text,
    -- | The unique identifier of the network in which the member is created.
    CreateMember -> Text
networkId :: Prelude.Text,
    -- | Member configuration parameters.
    CreateMember -> MemberConfiguration
memberConfiguration :: MemberConfiguration
  }
  deriving (CreateMember -> CreateMember -> Bool
(CreateMember -> CreateMember -> Bool)
-> (CreateMember -> CreateMember -> Bool) -> Eq CreateMember
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateMember -> CreateMember -> Bool
$c/= :: CreateMember -> CreateMember -> Bool
== :: CreateMember -> CreateMember -> Bool
$c== :: CreateMember -> CreateMember -> Bool
Prelude.Eq, Int -> CreateMember -> ShowS
[CreateMember] -> ShowS
CreateMember -> String
(Int -> CreateMember -> ShowS)
-> (CreateMember -> String)
-> ([CreateMember] -> ShowS)
-> Show CreateMember
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateMember] -> ShowS
$cshowList :: [CreateMember] -> ShowS
show :: CreateMember -> String
$cshow :: CreateMember -> String
showsPrec :: Int -> CreateMember -> ShowS
$cshowsPrec :: Int -> CreateMember -> ShowS
Prelude.Show, (forall x. CreateMember -> Rep CreateMember x)
-> (forall x. Rep CreateMember x -> CreateMember)
-> Generic CreateMember
forall x. Rep CreateMember x -> CreateMember
forall x. CreateMember -> Rep CreateMember x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateMember x -> CreateMember
$cfrom :: forall x. CreateMember -> Rep CreateMember x
Prelude.Generic)

-- |
-- Create a value of 'CreateMember' 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:
--
-- 'clientRequestToken', 'createMember_clientRequestToken' - A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the operation. An idempotent operation completes no more
-- than one time. This identifier is required only if you make a service
-- request directly using an HTTP client. It is generated automatically if
-- you use an AWS SDK or the AWS CLI.
--
-- 'invitationId', 'createMember_invitationId' - The unique identifier of the invitation that is sent to the member to
-- join the network.
--
-- 'networkId', 'createMember_networkId' - The unique identifier of the network in which the member is created.
--
-- 'memberConfiguration', 'createMember_memberConfiguration' - Member configuration parameters.
newCreateMember ::
  -- | 'clientRequestToken'
  Prelude.Text ->
  -- | 'invitationId'
  Prelude.Text ->
  -- | 'networkId'
  Prelude.Text ->
  -- | 'memberConfiguration'
  MemberConfiguration ->
  CreateMember
newCreateMember :: Text -> Text -> Text -> MemberConfiguration -> CreateMember
newCreateMember
  Text
pClientRequestToken_
  Text
pInvitationId_
  Text
pNetworkId_
  MemberConfiguration
pMemberConfiguration_ =
    CreateMember' :: Text -> Text -> Text -> MemberConfiguration -> CreateMember
CreateMember'
      { $sel:clientRequestToken:CreateMember' :: Text
clientRequestToken =
          Text
pClientRequestToken_,
        $sel:invitationId:CreateMember' :: Text
invitationId = Text
pInvitationId_,
        $sel:networkId:CreateMember' :: Text
networkId = Text
pNetworkId_,
        $sel:memberConfiguration:CreateMember' :: MemberConfiguration
memberConfiguration = MemberConfiguration
pMemberConfiguration_
      }

-- | A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the operation. An idempotent operation completes no more
-- than one time. This identifier is required only if you make a service
-- request directly using an HTTP client. It is generated automatically if
-- you use an AWS SDK or the AWS CLI.
createMember_clientRequestToken :: Lens.Lens' CreateMember Prelude.Text
createMember_clientRequestToken :: (Text -> f Text) -> CreateMember -> f CreateMember
createMember_clientRequestToken = (CreateMember -> Text)
-> (CreateMember -> Text -> CreateMember)
-> Lens CreateMember CreateMember Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateMember' {Text
clientRequestToken :: Text
$sel:clientRequestToken:CreateMember' :: CreateMember -> Text
clientRequestToken} -> Text
clientRequestToken) (\s :: CreateMember
s@CreateMember' {} Text
a -> CreateMember
s {$sel:clientRequestToken:CreateMember' :: Text
clientRequestToken = Text
a} :: CreateMember)

-- | The unique identifier of the invitation that is sent to the member to
-- join the network.
createMember_invitationId :: Lens.Lens' CreateMember Prelude.Text
createMember_invitationId :: (Text -> f Text) -> CreateMember -> f CreateMember
createMember_invitationId = (CreateMember -> Text)
-> (CreateMember -> Text -> CreateMember)
-> Lens CreateMember CreateMember Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateMember' {Text
invitationId :: Text
$sel:invitationId:CreateMember' :: CreateMember -> Text
invitationId} -> Text
invitationId) (\s :: CreateMember
s@CreateMember' {} Text
a -> CreateMember
s {$sel:invitationId:CreateMember' :: Text
invitationId = Text
a} :: CreateMember)

-- | The unique identifier of the network in which the member is created.
createMember_networkId :: Lens.Lens' CreateMember Prelude.Text
createMember_networkId :: (Text -> f Text) -> CreateMember -> f CreateMember
createMember_networkId = (CreateMember -> Text)
-> (CreateMember -> Text -> CreateMember)
-> Lens CreateMember CreateMember Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateMember' {Text
networkId :: Text
$sel:networkId:CreateMember' :: CreateMember -> Text
networkId} -> Text
networkId) (\s :: CreateMember
s@CreateMember' {} Text
a -> CreateMember
s {$sel:networkId:CreateMember' :: Text
networkId = Text
a} :: CreateMember)

-- | Member configuration parameters.
createMember_memberConfiguration :: Lens.Lens' CreateMember MemberConfiguration
createMember_memberConfiguration :: (MemberConfiguration -> f MemberConfiguration)
-> CreateMember -> f CreateMember
createMember_memberConfiguration = (CreateMember -> MemberConfiguration)
-> (CreateMember -> MemberConfiguration -> CreateMember)
-> Lens
     CreateMember CreateMember MemberConfiguration MemberConfiguration
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateMember' {MemberConfiguration
memberConfiguration :: MemberConfiguration
$sel:memberConfiguration:CreateMember' :: CreateMember -> MemberConfiguration
memberConfiguration} -> MemberConfiguration
memberConfiguration) (\s :: CreateMember
s@CreateMember' {} MemberConfiguration
a -> CreateMember
s {$sel:memberConfiguration:CreateMember' :: MemberConfiguration
memberConfiguration = MemberConfiguration
a} :: CreateMember)

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

instance Prelude.NFData CreateMember

instance Core.ToHeaders CreateMember where
  toHeaders :: CreateMember -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateMember -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 CreateMember where
  toJSON :: CreateMember -> Value
toJSON CreateMember' {Text
MemberConfiguration
memberConfiguration :: MemberConfiguration
networkId :: Text
invitationId :: Text
clientRequestToken :: Text
$sel:memberConfiguration:CreateMember' :: CreateMember -> MemberConfiguration
$sel:networkId:CreateMember' :: CreateMember -> Text
$sel:invitationId:CreateMember' :: CreateMember -> Text
$sel:clientRequestToken:CreateMember' :: CreateMember -> 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
"ClientRequestToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clientRequestToken),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InvitationId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
invitationId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"MemberConfiguration" Text -> MemberConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= MemberConfiguration
memberConfiguration)
          ]
      )

instance Core.ToPath CreateMember where
  toPath :: CreateMember -> ByteString
toPath CreateMember' {Text
MemberConfiguration
memberConfiguration :: MemberConfiguration
networkId :: Text
invitationId :: Text
clientRequestToken :: Text
$sel:memberConfiguration:CreateMember' :: CreateMember -> MemberConfiguration
$sel:networkId:CreateMember' :: CreateMember -> Text
$sel:invitationId:CreateMember' :: CreateMember -> Text
$sel:clientRequestToken:CreateMember' :: CreateMember -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/networks/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
networkId, ByteString
"/members"]

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

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

-- |
-- Create a value of 'CreateMemberResponse' 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:
--
-- 'memberId', 'createMemberResponse_memberId' - The unique identifier of the member.
--
-- 'httpStatus', 'createMemberResponse_httpStatus' - The response's http status code.
newCreateMemberResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateMemberResponse
newCreateMemberResponse :: Int -> CreateMemberResponse
newCreateMemberResponse Int
pHttpStatus_ =
  CreateMemberResponse' :: Maybe Text -> Int -> CreateMemberResponse
CreateMemberResponse'
    { $sel:memberId:CreateMemberResponse' :: Maybe Text
memberId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateMemberResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The unique identifier of the member.
createMemberResponse_memberId :: Lens.Lens' CreateMemberResponse (Prelude.Maybe Prelude.Text)
createMemberResponse_memberId :: (Maybe Text -> f (Maybe Text))
-> CreateMemberResponse -> f CreateMemberResponse
createMemberResponse_memberId = (CreateMemberResponse -> Maybe Text)
-> (CreateMemberResponse -> Maybe Text -> CreateMemberResponse)
-> Lens
     CreateMemberResponse CreateMemberResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateMemberResponse' {Maybe Text
memberId :: Maybe Text
$sel:memberId:CreateMemberResponse' :: CreateMemberResponse -> Maybe Text
memberId} -> Maybe Text
memberId) (\s :: CreateMemberResponse
s@CreateMemberResponse' {} Maybe Text
a -> CreateMemberResponse
s {$sel:memberId:CreateMemberResponse' :: Maybe Text
memberId = Maybe Text
a} :: CreateMemberResponse)

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

instance Prelude.NFData CreateMemberResponse