{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.Consumer
-- 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)
module Amazonka.Kinesis.Types.Consumer where

import qualified Amazonka.Core as Core
import Amazonka.Kinesis.Types.ConsumerStatus
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents the details of the consumer you registered.
-- This type of object is returned by RegisterStreamConsumer.
--
-- /See:/ 'newConsumer' smart constructor.
data Consumer = Consumer'
  { -- | The name of the consumer is something you choose when you register the
    -- consumer.
    Consumer -> Text
consumerName :: Prelude.Text,
    -- | When you register a consumer, Kinesis Data Streams generates an ARN for
    -- it. You need this ARN to be able to call SubscribeToShard.
    --
    -- If you delete a consumer and then create a new one with the same name,
    -- it won\'t have the same ARN. That\'s because consumer ARNs contain the
    -- creation timestamp. This is important to keep in mind if you have IAM
    -- policies that reference consumer ARNs.
    Consumer -> Text
consumerARN :: Prelude.Text,
    -- | A consumer can\'t read data while in the @CREATING@ or @DELETING@
    -- states.
    Consumer -> ConsumerStatus
consumerStatus :: ConsumerStatus,
    Consumer -> POSIX
consumerCreationTimestamp :: Core.POSIX
  }
  deriving (Consumer -> Consumer -> Bool
(Consumer -> Consumer -> Bool)
-> (Consumer -> Consumer -> Bool) -> Eq Consumer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Consumer -> Consumer -> Bool
$c/= :: Consumer -> Consumer -> Bool
== :: Consumer -> Consumer -> Bool
$c== :: Consumer -> Consumer -> Bool
Prelude.Eq, ReadPrec [Consumer]
ReadPrec Consumer
Int -> ReadS Consumer
ReadS [Consumer]
(Int -> ReadS Consumer)
-> ReadS [Consumer]
-> ReadPrec Consumer
-> ReadPrec [Consumer]
-> Read Consumer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Consumer]
$creadListPrec :: ReadPrec [Consumer]
readPrec :: ReadPrec Consumer
$creadPrec :: ReadPrec Consumer
readList :: ReadS [Consumer]
$creadList :: ReadS [Consumer]
readsPrec :: Int -> ReadS Consumer
$creadsPrec :: Int -> ReadS Consumer
Prelude.Read, Int -> Consumer -> ShowS
[Consumer] -> ShowS
Consumer -> String
(Int -> Consumer -> ShowS)
-> (Consumer -> String) -> ([Consumer] -> ShowS) -> Show Consumer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Consumer] -> ShowS
$cshowList :: [Consumer] -> ShowS
show :: Consumer -> String
$cshow :: Consumer -> String
showsPrec :: Int -> Consumer -> ShowS
$cshowsPrec :: Int -> Consumer -> ShowS
Prelude.Show, (forall x. Consumer -> Rep Consumer x)
-> (forall x. Rep Consumer x -> Consumer) -> Generic Consumer
forall x. Rep Consumer x -> Consumer
forall x. Consumer -> Rep Consumer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Consumer x -> Consumer
$cfrom :: forall x. Consumer -> Rep Consumer x
Prelude.Generic)

-- |
-- Create a value of 'Consumer' 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:
--
-- 'consumerName', 'consumer_consumerName' - The name of the consumer is something you choose when you register the
-- consumer.
--
-- 'consumerARN', 'consumer_consumerARN' - When you register a consumer, Kinesis Data Streams generates an ARN for
-- it. You need this ARN to be able to call SubscribeToShard.
--
-- If you delete a consumer and then create a new one with the same name,
-- it won\'t have the same ARN. That\'s because consumer ARNs contain the
-- creation timestamp. This is important to keep in mind if you have IAM
-- policies that reference consumer ARNs.
--
-- 'consumerStatus', 'consumer_consumerStatus' - A consumer can\'t read data while in the @CREATING@ or @DELETING@
-- states.
--
-- 'consumerCreationTimestamp', 'consumer_consumerCreationTimestamp' -
newConsumer ::
  -- | 'consumerName'
  Prelude.Text ->
  -- | 'consumerARN'
  Prelude.Text ->
  -- | 'consumerStatus'
  ConsumerStatus ->
  -- | 'consumerCreationTimestamp'
  Prelude.UTCTime ->
  Consumer
newConsumer :: Text -> Text -> ConsumerStatus -> UTCTime -> Consumer
newConsumer
  Text
pConsumerName_
  Text
pConsumerARN_
  ConsumerStatus
pConsumerStatus_
  UTCTime
pConsumerCreationTimestamp_ =
    Consumer' :: Text -> Text -> ConsumerStatus -> POSIX -> Consumer
Consumer'
      { $sel:consumerName:Consumer' :: Text
consumerName = Text
pConsumerName_,
        $sel:consumerARN:Consumer' :: Text
consumerARN = Text
pConsumerARN_,
        $sel:consumerStatus:Consumer' :: ConsumerStatus
consumerStatus = ConsumerStatus
pConsumerStatus_,
        $sel:consumerCreationTimestamp:Consumer' :: POSIX
consumerCreationTimestamp =
          Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pConsumerCreationTimestamp_
      }

-- | The name of the consumer is something you choose when you register the
-- consumer.
consumer_consumerName :: Lens.Lens' Consumer Prelude.Text
consumer_consumerName :: (Text -> f Text) -> Consumer -> f Consumer
consumer_consumerName = (Consumer -> Text)
-> (Consumer -> Text -> Consumer)
-> Lens Consumer Consumer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Consumer' {Text
consumerName :: Text
$sel:consumerName:Consumer' :: Consumer -> Text
consumerName} -> Text
consumerName) (\s :: Consumer
s@Consumer' {} Text
a -> Consumer
s {$sel:consumerName:Consumer' :: Text
consumerName = Text
a} :: Consumer)

-- | When you register a consumer, Kinesis Data Streams generates an ARN for
-- it. You need this ARN to be able to call SubscribeToShard.
--
-- If you delete a consumer and then create a new one with the same name,
-- it won\'t have the same ARN. That\'s because consumer ARNs contain the
-- creation timestamp. This is important to keep in mind if you have IAM
-- policies that reference consumer ARNs.
consumer_consumerARN :: Lens.Lens' Consumer Prelude.Text
consumer_consumerARN :: (Text -> f Text) -> Consumer -> f Consumer
consumer_consumerARN = (Consumer -> Text)
-> (Consumer -> Text -> Consumer)
-> Lens Consumer Consumer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Consumer' {Text
consumerARN :: Text
$sel:consumerARN:Consumer' :: Consumer -> Text
consumerARN} -> Text
consumerARN) (\s :: Consumer
s@Consumer' {} Text
a -> Consumer
s {$sel:consumerARN:Consumer' :: Text
consumerARN = Text
a} :: Consumer)

-- | A consumer can\'t read data while in the @CREATING@ or @DELETING@
-- states.
consumer_consumerStatus :: Lens.Lens' Consumer ConsumerStatus
consumer_consumerStatus :: (ConsumerStatus -> f ConsumerStatus) -> Consumer -> f Consumer
consumer_consumerStatus = (Consumer -> ConsumerStatus)
-> (Consumer -> ConsumerStatus -> Consumer)
-> Lens Consumer Consumer ConsumerStatus ConsumerStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Consumer' {ConsumerStatus
consumerStatus :: ConsumerStatus
$sel:consumerStatus:Consumer' :: Consumer -> ConsumerStatus
consumerStatus} -> ConsumerStatus
consumerStatus) (\s :: Consumer
s@Consumer' {} ConsumerStatus
a -> Consumer
s {$sel:consumerStatus:Consumer' :: ConsumerStatus
consumerStatus = ConsumerStatus
a} :: Consumer)

-- |
consumer_consumerCreationTimestamp :: Lens.Lens' Consumer Prelude.UTCTime
consumer_consumerCreationTimestamp :: (UTCTime -> f UTCTime) -> Consumer -> f Consumer
consumer_consumerCreationTimestamp = (Consumer -> POSIX)
-> (Consumer -> POSIX -> Consumer)
-> Lens Consumer Consumer POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Consumer' {POSIX
consumerCreationTimestamp :: POSIX
$sel:consumerCreationTimestamp:Consumer' :: Consumer -> POSIX
consumerCreationTimestamp} -> POSIX
consumerCreationTimestamp) (\s :: Consumer
s@Consumer' {} POSIX
a -> Consumer
s {$sel:consumerCreationTimestamp:Consumer' :: POSIX
consumerCreationTimestamp = POSIX
a} :: Consumer) ((POSIX -> f POSIX) -> Consumer -> f Consumer)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> Consumer
-> f Consumer
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Core.FromJSON Consumer where
  parseJSON :: Value -> Parser Consumer
parseJSON =
    String -> (Object -> Parser Consumer) -> Value -> Parser Consumer
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Consumer"
      ( \Object
x ->
          Text -> Text -> ConsumerStatus -> POSIX -> Consumer
Consumer'
            (Text -> Text -> ConsumerStatus -> POSIX -> Consumer)
-> Parser Text
-> Parser (Text -> ConsumerStatus -> POSIX -> Consumer)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ConsumerName")
            Parser (Text -> ConsumerStatus -> POSIX -> Consumer)
-> Parser Text -> Parser (ConsumerStatus -> POSIX -> Consumer)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ConsumerARN")
            Parser (ConsumerStatus -> POSIX -> Consumer)
-> Parser ConsumerStatus -> Parser (POSIX -> Consumer)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ConsumerStatus
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ConsumerStatus")
            Parser (POSIX -> Consumer) -> Parser POSIX -> Parser Consumer
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ConsumerCreationTimestamp")
      )

instance Prelude.Hashable Consumer

instance Prelude.NFData Consumer