{-# 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.CloudWatchEvents.Types.KinesisParameters
-- 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.CloudWatchEvents.Types.KinesisParameters where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | This object enables you to specify a JSON path to extract from the event
-- and use as the partition key for the Amazon Kinesis data stream, so that
-- you can control the shard to which the event goes. If you do not include
-- this parameter, the default is to use the @eventId@ as the partition
-- key.
--
-- /See:/ 'newKinesisParameters' smart constructor.
data KinesisParameters = KinesisParameters'
  { -- | The JSON path to be extracted from the event and used as the partition
    -- key. For more information, see
    -- <https://docs.aws.amazon.com/streams/latest/dev/key-concepts.html#partition-key Amazon Kinesis Streams Key Concepts>
    -- in the /Amazon Kinesis Streams Developer Guide/.
    KinesisParameters -> Text
partitionKeyPath :: Prelude.Text
  }
  deriving (KinesisParameters -> KinesisParameters -> Bool
(KinesisParameters -> KinesisParameters -> Bool)
-> (KinesisParameters -> KinesisParameters -> Bool)
-> Eq KinesisParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KinesisParameters -> KinesisParameters -> Bool
$c/= :: KinesisParameters -> KinesisParameters -> Bool
== :: KinesisParameters -> KinesisParameters -> Bool
$c== :: KinesisParameters -> KinesisParameters -> Bool
Prelude.Eq, ReadPrec [KinesisParameters]
ReadPrec KinesisParameters
Int -> ReadS KinesisParameters
ReadS [KinesisParameters]
(Int -> ReadS KinesisParameters)
-> ReadS [KinesisParameters]
-> ReadPrec KinesisParameters
-> ReadPrec [KinesisParameters]
-> Read KinesisParameters
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KinesisParameters]
$creadListPrec :: ReadPrec [KinesisParameters]
readPrec :: ReadPrec KinesisParameters
$creadPrec :: ReadPrec KinesisParameters
readList :: ReadS [KinesisParameters]
$creadList :: ReadS [KinesisParameters]
readsPrec :: Int -> ReadS KinesisParameters
$creadsPrec :: Int -> ReadS KinesisParameters
Prelude.Read, Int -> KinesisParameters -> ShowS
[KinesisParameters] -> ShowS
KinesisParameters -> String
(Int -> KinesisParameters -> ShowS)
-> (KinesisParameters -> String)
-> ([KinesisParameters] -> ShowS)
-> Show KinesisParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KinesisParameters] -> ShowS
$cshowList :: [KinesisParameters] -> ShowS
show :: KinesisParameters -> String
$cshow :: KinesisParameters -> String
showsPrec :: Int -> KinesisParameters -> ShowS
$cshowsPrec :: Int -> KinesisParameters -> ShowS
Prelude.Show, (forall x. KinesisParameters -> Rep KinesisParameters x)
-> (forall x. Rep KinesisParameters x -> KinesisParameters)
-> Generic KinesisParameters
forall x. Rep KinesisParameters x -> KinesisParameters
forall x. KinesisParameters -> Rep KinesisParameters x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KinesisParameters x -> KinesisParameters
$cfrom :: forall x. KinesisParameters -> Rep KinesisParameters x
Prelude.Generic)

-- |
-- Create a value of 'KinesisParameters' 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:
--
-- 'partitionKeyPath', 'kinesisParameters_partitionKeyPath' - The JSON path to be extracted from the event and used as the partition
-- key. For more information, see
-- <https://docs.aws.amazon.com/streams/latest/dev/key-concepts.html#partition-key Amazon Kinesis Streams Key Concepts>
-- in the /Amazon Kinesis Streams Developer Guide/.
newKinesisParameters ::
  -- | 'partitionKeyPath'
  Prelude.Text ->
  KinesisParameters
newKinesisParameters :: Text -> KinesisParameters
newKinesisParameters Text
pPartitionKeyPath_ =
  KinesisParameters' :: Text -> KinesisParameters
KinesisParameters'
    { $sel:partitionKeyPath:KinesisParameters' :: Text
partitionKeyPath =
        Text
pPartitionKeyPath_
    }

-- | The JSON path to be extracted from the event and used as the partition
-- key. For more information, see
-- <https://docs.aws.amazon.com/streams/latest/dev/key-concepts.html#partition-key Amazon Kinesis Streams Key Concepts>
-- in the /Amazon Kinesis Streams Developer Guide/.
kinesisParameters_partitionKeyPath :: Lens.Lens' KinesisParameters Prelude.Text
kinesisParameters_partitionKeyPath :: (Text -> f Text) -> KinesisParameters -> f KinesisParameters
kinesisParameters_partitionKeyPath = (KinesisParameters -> Text)
-> (KinesisParameters -> Text -> KinesisParameters)
-> Lens KinesisParameters KinesisParameters Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KinesisParameters' {Text
partitionKeyPath :: Text
$sel:partitionKeyPath:KinesisParameters' :: KinesisParameters -> Text
partitionKeyPath} -> Text
partitionKeyPath) (\s :: KinesisParameters
s@KinesisParameters' {} Text
a -> KinesisParameters
s {$sel:partitionKeyPath:KinesisParameters' :: Text
partitionKeyPath = Text
a} :: KinesisParameters)

instance Core.FromJSON KinesisParameters where
  parseJSON :: Value -> Parser KinesisParameters
parseJSON =
    String
-> (Object -> Parser KinesisParameters)
-> Value
-> Parser KinesisParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"KinesisParameters"
      ( \Object
x ->
          Text -> KinesisParameters
KinesisParameters'
            (Text -> KinesisParameters)
-> Parser Text -> Parser KinesisParameters
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
"PartitionKeyPath")
      )

instance Prelude.Hashable KinesisParameters

instance Prelude.NFData KinesisParameters

instance Core.ToJSON KinesisParameters where
  toJSON :: KinesisParameters -> Value
toJSON KinesisParameters' {Text
partitionKeyPath :: Text
$sel:partitionKeyPath:KinesisParameters' :: KinesisParameters -> 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
"PartitionKeyPath" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
partitionKeyPath)
          ]
      )