{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudWatchEvents.Types.KinesisParameters where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $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 :: Lens' KinesisParameters Text
kinesisParameters_partitionKeyPath = 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 Data.FromJSON KinesisParameters where
  parseJSON :: Value -> Parser KinesisParameters
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"KinesisParameters"
      ( \Object
x ->
          Text -> KinesisParameters
KinesisParameters'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"PartitionKeyPath")
      )

instance Prelude.Hashable KinesisParameters where
  hashWithSalt :: Int -> KinesisParameters -> Int
hashWithSalt Int
_salt KinesisParameters' {Text
partitionKeyPath :: Text
$sel:partitionKeyPath:KinesisParameters' :: KinesisParameters -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
partitionKeyPath

instance Prelude.NFData KinesisParameters where
  rnf :: KinesisParameters -> ()
rnf KinesisParameters' {Text
partitionKeyPath :: Text
$sel:partitionKeyPath:KinesisParameters' :: KinesisParameters -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
partitionKeyPath

instance Data.ToJSON KinesisParameters where
  toJSON :: KinesisParameters -> Value
toJSON KinesisParameters' {Text
partitionKeyPath :: Text
$sel:partitionKeyPath:KinesisParameters' :: KinesisParameters -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"PartitionKeyPath" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
partitionKeyPath)
          ]
      )