{-# 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.Kinesis.RegisterStreamConsumer
-- 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)
--
-- Registers a consumer with a Kinesis data stream. When you use this
-- operation, the consumer you register can then call SubscribeToShard to
-- receive data from the stream using enhanced fan-out, at a rate of up to
-- 2 MiB per second for every shard you subscribe to. This rate is
-- unaffected by the total number of consumers that read from the same
-- stream.
--
-- You can register up to 20 consumers per stream. A given consumer can
-- only be registered with one stream at a time.
--
-- For an example of how to use this operations, see
-- </streams/latest/dev/building-enhanced-consumers-api.html Enhanced Fan-Out Using the Kinesis Data Streams API>.
--
-- The use of this operation has a limit of five transactions per second
-- per account. Also, only 5 consumers can be created simultaneously. In
-- other words, you cannot have more than 5 consumers in a @CREATING@
-- status at the same time. Registering a 6th consumer while there are 5 in
-- a @CREATING@ status results in a @LimitExceededException@.
module Amazonka.Kinesis.RegisterStreamConsumer
  ( -- * Creating a Request
    RegisterStreamConsumer (..),
    newRegisterStreamConsumer,

    -- * Request Lenses
    registerStreamConsumer_streamARN,
    registerStreamConsumer_consumerName,

    -- * Destructuring the Response
    RegisterStreamConsumerResponse (..),
    newRegisterStreamConsumerResponse,

    -- * Response Lenses
    registerStreamConsumerResponse_httpStatus,
    registerStreamConsumerResponse_consumer,
  )
where

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

-- | /See:/ 'newRegisterStreamConsumer' smart constructor.
data RegisterStreamConsumer = RegisterStreamConsumer'
  { -- | The ARN of the Kinesis data stream that you want to register the
    -- consumer with. For more info, see
    -- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-kinesis-streams Amazon Resource Names (ARNs) and AWS Service Namespaces>.
    RegisterStreamConsumer -> Text
streamARN :: Prelude.Text,
    -- | For a given Kinesis data stream, each consumer must have a unique name.
    -- However, consumer names don\'t have to be unique across data streams.
    RegisterStreamConsumer -> Text
consumerName :: Prelude.Text
  }
  deriving (RegisterStreamConsumer -> RegisterStreamConsumer -> Bool
(RegisterStreamConsumer -> RegisterStreamConsumer -> Bool)
-> (RegisterStreamConsumer -> RegisterStreamConsumer -> Bool)
-> Eq RegisterStreamConsumer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterStreamConsumer -> RegisterStreamConsumer -> Bool
$c/= :: RegisterStreamConsumer -> RegisterStreamConsumer -> Bool
== :: RegisterStreamConsumer -> RegisterStreamConsumer -> Bool
$c== :: RegisterStreamConsumer -> RegisterStreamConsumer -> Bool
Prelude.Eq, ReadPrec [RegisterStreamConsumer]
ReadPrec RegisterStreamConsumer
Int -> ReadS RegisterStreamConsumer
ReadS [RegisterStreamConsumer]
(Int -> ReadS RegisterStreamConsumer)
-> ReadS [RegisterStreamConsumer]
-> ReadPrec RegisterStreamConsumer
-> ReadPrec [RegisterStreamConsumer]
-> Read RegisterStreamConsumer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterStreamConsumer]
$creadListPrec :: ReadPrec [RegisterStreamConsumer]
readPrec :: ReadPrec RegisterStreamConsumer
$creadPrec :: ReadPrec RegisterStreamConsumer
readList :: ReadS [RegisterStreamConsumer]
$creadList :: ReadS [RegisterStreamConsumer]
readsPrec :: Int -> ReadS RegisterStreamConsumer
$creadsPrec :: Int -> ReadS RegisterStreamConsumer
Prelude.Read, Int -> RegisterStreamConsumer -> ShowS
[RegisterStreamConsumer] -> ShowS
RegisterStreamConsumer -> String
(Int -> RegisterStreamConsumer -> ShowS)
-> (RegisterStreamConsumer -> String)
-> ([RegisterStreamConsumer] -> ShowS)
-> Show RegisterStreamConsumer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterStreamConsumer] -> ShowS
$cshowList :: [RegisterStreamConsumer] -> ShowS
show :: RegisterStreamConsumer -> String
$cshow :: RegisterStreamConsumer -> String
showsPrec :: Int -> RegisterStreamConsumer -> ShowS
$cshowsPrec :: Int -> RegisterStreamConsumer -> ShowS
Prelude.Show, (forall x. RegisterStreamConsumer -> Rep RegisterStreamConsumer x)
-> (forall x.
    Rep RegisterStreamConsumer x -> RegisterStreamConsumer)
-> Generic RegisterStreamConsumer
forall x. Rep RegisterStreamConsumer x -> RegisterStreamConsumer
forall x. RegisterStreamConsumer -> Rep RegisterStreamConsumer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterStreamConsumer x -> RegisterStreamConsumer
$cfrom :: forall x. RegisterStreamConsumer -> Rep RegisterStreamConsumer x
Prelude.Generic)

-- |
-- Create a value of 'RegisterStreamConsumer' 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:
--
-- 'streamARN', 'registerStreamConsumer_streamARN' - The ARN of the Kinesis data stream that you want to register the
-- consumer with. For more info, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-kinesis-streams Amazon Resource Names (ARNs) and AWS Service Namespaces>.
--
-- 'consumerName', 'registerStreamConsumer_consumerName' - For a given Kinesis data stream, each consumer must have a unique name.
-- However, consumer names don\'t have to be unique across data streams.
newRegisterStreamConsumer ::
  -- | 'streamARN'
  Prelude.Text ->
  -- | 'consumerName'
  Prelude.Text ->
  RegisterStreamConsumer
newRegisterStreamConsumer :: Text -> Text -> RegisterStreamConsumer
newRegisterStreamConsumer Text
pStreamARN_ Text
pConsumerName_ =
  RegisterStreamConsumer' :: Text -> Text -> RegisterStreamConsumer
RegisterStreamConsumer'
    { $sel:streamARN:RegisterStreamConsumer' :: Text
streamARN = Text
pStreamARN_,
      $sel:consumerName:RegisterStreamConsumer' :: Text
consumerName = Text
pConsumerName_
    }

-- | The ARN of the Kinesis data stream that you want to register the
-- consumer with. For more info, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-kinesis-streams Amazon Resource Names (ARNs) and AWS Service Namespaces>.
registerStreamConsumer_streamARN :: Lens.Lens' RegisterStreamConsumer Prelude.Text
registerStreamConsumer_streamARN :: (Text -> f Text)
-> RegisterStreamConsumer -> f RegisterStreamConsumer
registerStreamConsumer_streamARN = (RegisterStreamConsumer -> Text)
-> (RegisterStreamConsumer -> Text -> RegisterStreamConsumer)
-> Lens RegisterStreamConsumer RegisterStreamConsumer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterStreamConsumer' {Text
streamARN :: Text
$sel:streamARN:RegisterStreamConsumer' :: RegisterStreamConsumer -> Text
streamARN} -> Text
streamARN) (\s :: RegisterStreamConsumer
s@RegisterStreamConsumer' {} Text
a -> RegisterStreamConsumer
s {$sel:streamARN:RegisterStreamConsumer' :: Text
streamARN = Text
a} :: RegisterStreamConsumer)

-- | For a given Kinesis data stream, each consumer must have a unique name.
-- However, consumer names don\'t have to be unique across data streams.
registerStreamConsumer_consumerName :: Lens.Lens' RegisterStreamConsumer Prelude.Text
registerStreamConsumer_consumerName :: (Text -> f Text)
-> RegisterStreamConsumer -> f RegisterStreamConsumer
registerStreamConsumer_consumerName = (RegisterStreamConsumer -> Text)
-> (RegisterStreamConsumer -> Text -> RegisterStreamConsumer)
-> Lens RegisterStreamConsumer RegisterStreamConsumer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterStreamConsumer' {Text
consumerName :: Text
$sel:consumerName:RegisterStreamConsumer' :: RegisterStreamConsumer -> Text
consumerName} -> Text
consumerName) (\s :: RegisterStreamConsumer
s@RegisterStreamConsumer' {} Text
a -> RegisterStreamConsumer
s {$sel:consumerName:RegisterStreamConsumer' :: Text
consumerName = Text
a} :: RegisterStreamConsumer)

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

instance Prelude.Hashable RegisterStreamConsumer

instance Prelude.NFData RegisterStreamConsumer

instance Core.ToHeaders RegisterStreamConsumer where
  toHeaders :: RegisterStreamConsumer -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RegisterStreamConsumer -> 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
"Kinesis_20131202.RegisterStreamConsumer" ::
                          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 RegisterStreamConsumer where
  toJSON :: RegisterStreamConsumer -> Value
toJSON RegisterStreamConsumer' {Text
consumerName :: Text
streamARN :: Text
$sel:consumerName:RegisterStreamConsumer' :: RegisterStreamConsumer -> Text
$sel:streamARN:RegisterStreamConsumer' :: RegisterStreamConsumer -> 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
"StreamARN" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
streamARN),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ConsumerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
consumerName)
          ]
      )

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

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

-- | /See:/ 'newRegisterStreamConsumerResponse' smart constructor.
data RegisterStreamConsumerResponse = RegisterStreamConsumerResponse'
  { -- | The response's http status code.
    RegisterStreamConsumerResponse -> Int
httpStatus :: Prelude.Int,
    -- | An object that represents the details of the consumer you registered.
    -- When you register a consumer, it gets an ARN that is generated by
    -- Kinesis Data Streams.
    RegisterStreamConsumerResponse -> Consumer
consumer :: Consumer
  }
  deriving (RegisterStreamConsumerResponse
-> RegisterStreamConsumerResponse -> Bool
(RegisterStreamConsumerResponse
 -> RegisterStreamConsumerResponse -> Bool)
-> (RegisterStreamConsumerResponse
    -> RegisterStreamConsumerResponse -> Bool)
-> Eq RegisterStreamConsumerResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterStreamConsumerResponse
-> RegisterStreamConsumerResponse -> Bool
$c/= :: RegisterStreamConsumerResponse
-> RegisterStreamConsumerResponse -> Bool
== :: RegisterStreamConsumerResponse
-> RegisterStreamConsumerResponse -> Bool
$c== :: RegisterStreamConsumerResponse
-> RegisterStreamConsumerResponse -> Bool
Prelude.Eq, ReadPrec [RegisterStreamConsumerResponse]
ReadPrec RegisterStreamConsumerResponse
Int -> ReadS RegisterStreamConsumerResponse
ReadS [RegisterStreamConsumerResponse]
(Int -> ReadS RegisterStreamConsumerResponse)
-> ReadS [RegisterStreamConsumerResponse]
-> ReadPrec RegisterStreamConsumerResponse
-> ReadPrec [RegisterStreamConsumerResponse]
-> Read RegisterStreamConsumerResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterStreamConsumerResponse]
$creadListPrec :: ReadPrec [RegisterStreamConsumerResponse]
readPrec :: ReadPrec RegisterStreamConsumerResponse
$creadPrec :: ReadPrec RegisterStreamConsumerResponse
readList :: ReadS [RegisterStreamConsumerResponse]
$creadList :: ReadS [RegisterStreamConsumerResponse]
readsPrec :: Int -> ReadS RegisterStreamConsumerResponse
$creadsPrec :: Int -> ReadS RegisterStreamConsumerResponse
Prelude.Read, Int -> RegisterStreamConsumerResponse -> ShowS
[RegisterStreamConsumerResponse] -> ShowS
RegisterStreamConsumerResponse -> String
(Int -> RegisterStreamConsumerResponse -> ShowS)
-> (RegisterStreamConsumerResponse -> String)
-> ([RegisterStreamConsumerResponse] -> ShowS)
-> Show RegisterStreamConsumerResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterStreamConsumerResponse] -> ShowS
$cshowList :: [RegisterStreamConsumerResponse] -> ShowS
show :: RegisterStreamConsumerResponse -> String
$cshow :: RegisterStreamConsumerResponse -> String
showsPrec :: Int -> RegisterStreamConsumerResponse -> ShowS
$cshowsPrec :: Int -> RegisterStreamConsumerResponse -> ShowS
Prelude.Show, (forall x.
 RegisterStreamConsumerResponse
 -> Rep RegisterStreamConsumerResponse x)
-> (forall x.
    Rep RegisterStreamConsumerResponse x
    -> RegisterStreamConsumerResponse)
-> Generic RegisterStreamConsumerResponse
forall x.
Rep RegisterStreamConsumerResponse x
-> RegisterStreamConsumerResponse
forall x.
RegisterStreamConsumerResponse
-> Rep RegisterStreamConsumerResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RegisterStreamConsumerResponse x
-> RegisterStreamConsumerResponse
$cfrom :: forall x.
RegisterStreamConsumerResponse
-> Rep RegisterStreamConsumerResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterStreamConsumerResponse' 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:
--
-- 'httpStatus', 'registerStreamConsumerResponse_httpStatus' - The response's http status code.
--
-- 'consumer', 'registerStreamConsumerResponse_consumer' - An object that represents the details of the consumer you registered.
-- When you register a consumer, it gets an ARN that is generated by
-- Kinesis Data Streams.
newRegisterStreamConsumerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'consumer'
  Consumer ->
  RegisterStreamConsumerResponse
newRegisterStreamConsumerResponse :: Int -> Consumer -> RegisterStreamConsumerResponse
newRegisterStreamConsumerResponse
  Int
pHttpStatus_
  Consumer
pConsumer_ =
    RegisterStreamConsumerResponse' :: Int -> Consumer -> RegisterStreamConsumerResponse
RegisterStreamConsumerResponse'
      { $sel:httpStatus:RegisterStreamConsumerResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:consumer:RegisterStreamConsumerResponse' :: Consumer
consumer = Consumer
pConsumer_
      }

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

-- | An object that represents the details of the consumer you registered.
-- When you register a consumer, it gets an ARN that is generated by
-- Kinesis Data Streams.
registerStreamConsumerResponse_consumer :: Lens.Lens' RegisterStreamConsumerResponse Consumer
registerStreamConsumerResponse_consumer :: (Consumer -> f Consumer)
-> RegisterStreamConsumerResponse
-> f RegisterStreamConsumerResponse
registerStreamConsumerResponse_consumer = (RegisterStreamConsumerResponse -> Consumer)
-> (RegisterStreamConsumerResponse
    -> Consumer -> RegisterStreamConsumerResponse)
-> Lens
     RegisterStreamConsumerResponse
     RegisterStreamConsumerResponse
     Consumer
     Consumer
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterStreamConsumerResponse' {Consumer
consumer :: Consumer
$sel:consumer:RegisterStreamConsumerResponse' :: RegisterStreamConsumerResponse -> Consumer
consumer} -> Consumer
consumer) (\s :: RegisterStreamConsumerResponse
s@RegisterStreamConsumerResponse' {} Consumer
a -> RegisterStreamConsumerResponse
s {$sel:consumer:RegisterStreamConsumerResponse' :: Consumer
consumer = Consumer
a} :: RegisterStreamConsumerResponse)

instance
  Prelude.NFData
    RegisterStreamConsumerResponse