{-# 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.InputTransformer
-- 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.InputTransformer where

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

-- | Contains the parameters needed for you to provide custom input to a
-- target based on one or more pieces of data extracted from the event.
--
-- /See:/ 'newInputTransformer' smart constructor.
data InputTransformer = InputTransformer'
  { -- | Map of JSON paths to be extracted from the event. You can then insert
    -- these in the template in @InputTemplate@ to produce the output you want
    -- to be sent to the target.
    --
    -- @InputPathsMap@ is an array key-value pairs, where each value is a valid
    -- JSON path. You can have as many as 100 key-value pairs. You must use
    -- JSON dot notation, not bracket notation.
    --
    -- The keys cannot start with \"Amazon Web Services.\"
    InputTransformer -> Maybe (HashMap Text Text)
inputPathsMap :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | Input template where you specify placeholders that will be filled with
    -- the values of the keys from @InputPathsMap@ to customize the data sent
    -- to the target. Enclose each @InputPathsMaps@ value in brackets:
    -- \</value/> The InputTemplate must be valid JSON.
    --
    -- If @InputTemplate@ is a JSON object (surrounded by curly braces), the
    -- following restrictions apply:
    --
    -- -   The placeholder cannot be used as an object key.
    --
    -- The following example shows the syntax for using @InputPathsMap@ and
    -- @InputTemplate@.
    --
    -- @ \"InputTransformer\":@
    --
    -- @{@
    --
    -- @\"InputPathsMap\": {\"instance\": \"$.detail.instance\",\"status\": \"$.detail.status\"},@
    --
    -- @\"InputTemplate\": \"\<instance> is in state \<status>\"@
    --
    -- @}@
    --
    -- To have the @InputTemplate@ include quote marks within a JSON string,
    -- escape each quote marks with a slash, as in the following example:
    --
    -- @ \"InputTransformer\":@
    --
    -- @{@
    --
    -- @\"InputPathsMap\": {\"instance\": \"$.detail.instance\",\"status\": \"$.detail.status\"},@
    --
    -- @\"InputTemplate\": \"\<instance> is in state \\\"\<status>\\\"\"@
    --
    -- @}@
    --
    -- The @InputTemplate@ can also be valid JSON with varibles in quotes or
    -- out, as in the following example:
    --
    -- @ \"InputTransformer\":@
    --
    -- @{@
    --
    -- @\"InputPathsMap\": {\"instance\": \"$.detail.instance\",\"status\": \"$.detail.status\"},@
    --
    -- @\"InputTemplate\": \'{\"myInstance\": \<instance>,\"myStatus\": \"\<instance> is in state \\\"\<status>\\\"\"}\'@
    --
    -- @}@
    InputTransformer -> Text
inputTemplate :: Prelude.Text
  }
  deriving (InputTransformer -> InputTransformer -> Bool
(InputTransformer -> InputTransformer -> Bool)
-> (InputTransformer -> InputTransformer -> Bool)
-> Eq InputTransformer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InputTransformer -> InputTransformer -> Bool
$c/= :: InputTransformer -> InputTransformer -> Bool
== :: InputTransformer -> InputTransformer -> Bool
$c== :: InputTransformer -> InputTransformer -> Bool
Prelude.Eq, ReadPrec [InputTransformer]
ReadPrec InputTransformer
Int -> ReadS InputTransformer
ReadS [InputTransformer]
(Int -> ReadS InputTransformer)
-> ReadS [InputTransformer]
-> ReadPrec InputTransformer
-> ReadPrec [InputTransformer]
-> Read InputTransformer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InputTransformer]
$creadListPrec :: ReadPrec [InputTransformer]
readPrec :: ReadPrec InputTransformer
$creadPrec :: ReadPrec InputTransformer
readList :: ReadS [InputTransformer]
$creadList :: ReadS [InputTransformer]
readsPrec :: Int -> ReadS InputTransformer
$creadsPrec :: Int -> ReadS InputTransformer
Prelude.Read, Int -> InputTransformer -> ShowS
[InputTransformer] -> ShowS
InputTransformer -> String
(Int -> InputTransformer -> ShowS)
-> (InputTransformer -> String)
-> ([InputTransformer] -> ShowS)
-> Show InputTransformer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InputTransformer] -> ShowS
$cshowList :: [InputTransformer] -> ShowS
show :: InputTransformer -> String
$cshow :: InputTransformer -> String
showsPrec :: Int -> InputTransformer -> ShowS
$cshowsPrec :: Int -> InputTransformer -> ShowS
Prelude.Show, (forall x. InputTransformer -> Rep InputTransformer x)
-> (forall x. Rep InputTransformer x -> InputTransformer)
-> Generic InputTransformer
forall x. Rep InputTransformer x -> InputTransformer
forall x. InputTransformer -> Rep InputTransformer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InputTransformer x -> InputTransformer
$cfrom :: forall x. InputTransformer -> Rep InputTransformer x
Prelude.Generic)

-- |
-- Create a value of 'InputTransformer' 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:
--
-- 'inputPathsMap', 'inputTransformer_inputPathsMap' - Map of JSON paths to be extracted from the event. You can then insert
-- these in the template in @InputTemplate@ to produce the output you want
-- to be sent to the target.
--
-- @InputPathsMap@ is an array key-value pairs, where each value is a valid
-- JSON path. You can have as many as 100 key-value pairs. You must use
-- JSON dot notation, not bracket notation.
--
-- The keys cannot start with \"Amazon Web Services.\"
--
-- 'inputTemplate', 'inputTransformer_inputTemplate' - Input template where you specify placeholders that will be filled with
-- the values of the keys from @InputPathsMap@ to customize the data sent
-- to the target. Enclose each @InputPathsMaps@ value in brackets:
-- \</value/> The InputTemplate must be valid JSON.
--
-- If @InputTemplate@ is a JSON object (surrounded by curly braces), the
-- following restrictions apply:
--
-- -   The placeholder cannot be used as an object key.
--
-- The following example shows the syntax for using @InputPathsMap@ and
-- @InputTemplate@.
--
-- @ \"InputTransformer\":@
--
-- @{@
--
-- @\"InputPathsMap\": {\"instance\": \"$.detail.instance\",\"status\": \"$.detail.status\"},@
--
-- @\"InputTemplate\": \"\<instance> is in state \<status>\"@
--
-- @}@
--
-- To have the @InputTemplate@ include quote marks within a JSON string,
-- escape each quote marks with a slash, as in the following example:
--
-- @ \"InputTransformer\":@
--
-- @{@
--
-- @\"InputPathsMap\": {\"instance\": \"$.detail.instance\",\"status\": \"$.detail.status\"},@
--
-- @\"InputTemplate\": \"\<instance> is in state \\\"\<status>\\\"\"@
--
-- @}@
--
-- The @InputTemplate@ can also be valid JSON with varibles in quotes or
-- out, as in the following example:
--
-- @ \"InputTransformer\":@
--
-- @{@
--
-- @\"InputPathsMap\": {\"instance\": \"$.detail.instance\",\"status\": \"$.detail.status\"},@
--
-- @\"InputTemplate\": \'{\"myInstance\": \<instance>,\"myStatus\": \"\<instance> is in state \\\"\<status>\\\"\"}\'@
--
-- @}@
newInputTransformer ::
  -- | 'inputTemplate'
  Prelude.Text ->
  InputTransformer
newInputTransformer :: Text -> InputTransformer
newInputTransformer Text
pInputTemplate_ =
  InputTransformer' :: Maybe (HashMap Text Text) -> Text -> InputTransformer
InputTransformer'
    { $sel:inputPathsMap:InputTransformer' :: Maybe (HashMap Text Text)
inputPathsMap = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:inputTemplate:InputTransformer' :: Text
inputTemplate = Text
pInputTemplate_
    }

-- | Map of JSON paths to be extracted from the event. You can then insert
-- these in the template in @InputTemplate@ to produce the output you want
-- to be sent to the target.
--
-- @InputPathsMap@ is an array key-value pairs, where each value is a valid
-- JSON path. You can have as many as 100 key-value pairs. You must use
-- JSON dot notation, not bracket notation.
--
-- The keys cannot start with \"Amazon Web Services.\"
inputTransformer_inputPathsMap :: Lens.Lens' InputTransformer (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
inputTransformer_inputPathsMap :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> InputTransformer -> f InputTransformer
inputTransformer_inputPathsMap = (InputTransformer -> Maybe (HashMap Text Text))
-> (InputTransformer
    -> Maybe (HashMap Text Text) -> InputTransformer)
-> Lens
     InputTransformer
     InputTransformer
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InputTransformer' {Maybe (HashMap Text Text)
inputPathsMap :: Maybe (HashMap Text Text)
$sel:inputPathsMap:InputTransformer' :: InputTransformer -> Maybe (HashMap Text Text)
inputPathsMap} -> Maybe (HashMap Text Text)
inputPathsMap) (\s :: InputTransformer
s@InputTransformer' {} Maybe (HashMap Text Text)
a -> InputTransformer
s {$sel:inputPathsMap:InputTransformer' :: Maybe (HashMap Text Text)
inputPathsMap = Maybe (HashMap Text Text)
a} :: InputTransformer) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> InputTransformer -> f InputTransformer)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> InputTransformer
-> f InputTransformer
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Input template where you specify placeholders that will be filled with
-- the values of the keys from @InputPathsMap@ to customize the data sent
-- to the target. Enclose each @InputPathsMaps@ value in brackets:
-- \</value/> The InputTemplate must be valid JSON.
--
-- If @InputTemplate@ is a JSON object (surrounded by curly braces), the
-- following restrictions apply:
--
-- -   The placeholder cannot be used as an object key.
--
-- The following example shows the syntax for using @InputPathsMap@ and
-- @InputTemplate@.
--
-- @ \"InputTransformer\":@
--
-- @{@
--
-- @\"InputPathsMap\": {\"instance\": \"$.detail.instance\",\"status\": \"$.detail.status\"},@
--
-- @\"InputTemplate\": \"\<instance> is in state \<status>\"@
--
-- @}@
--
-- To have the @InputTemplate@ include quote marks within a JSON string,
-- escape each quote marks with a slash, as in the following example:
--
-- @ \"InputTransformer\":@
--
-- @{@
--
-- @\"InputPathsMap\": {\"instance\": \"$.detail.instance\",\"status\": \"$.detail.status\"},@
--
-- @\"InputTemplate\": \"\<instance> is in state \\\"\<status>\\\"\"@
--
-- @}@
--
-- The @InputTemplate@ can also be valid JSON with varibles in quotes or
-- out, as in the following example:
--
-- @ \"InputTransformer\":@
--
-- @{@
--
-- @\"InputPathsMap\": {\"instance\": \"$.detail.instance\",\"status\": \"$.detail.status\"},@
--
-- @\"InputTemplate\": \'{\"myInstance\": \<instance>,\"myStatus\": \"\<instance> is in state \\\"\<status>\\\"\"}\'@
--
-- @}@
inputTransformer_inputTemplate :: Lens.Lens' InputTransformer Prelude.Text
inputTransformer_inputTemplate :: (Text -> f Text) -> InputTransformer -> f InputTransformer
inputTransformer_inputTemplate = (InputTransformer -> Text)
-> (InputTransformer -> Text -> InputTransformer)
-> Lens InputTransformer InputTransformer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InputTransformer' {Text
inputTemplate :: Text
$sel:inputTemplate:InputTransformer' :: InputTransformer -> Text
inputTemplate} -> Text
inputTemplate) (\s :: InputTransformer
s@InputTransformer' {} Text
a -> InputTransformer
s {$sel:inputTemplate:InputTransformer' :: Text
inputTemplate = Text
a} :: InputTransformer)

instance Core.FromJSON InputTransformer where
  parseJSON :: Value -> Parser InputTransformer
parseJSON =
    String
-> (Object -> Parser InputTransformer)
-> Value
-> Parser InputTransformer
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InputTransformer"
      ( \Object
x ->
          Maybe (HashMap Text Text) -> Text -> InputTransformer
InputTransformer'
            (Maybe (HashMap Text Text) -> Text -> InputTransformer)
-> Parser (Maybe (HashMap Text Text))
-> Parser (Text -> InputTransformer)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"InputPathsMap" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> InputTransformer)
-> Parser Text -> Parser InputTransformer
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
"InputTemplate")
      )

instance Prelude.Hashable InputTransformer

instance Prelude.NFData InputTransformer

instance Core.ToJSON InputTransformer where
  toJSON :: InputTransformer -> Value
toJSON InputTransformer' {Maybe (HashMap Text Text)
Text
inputTemplate :: Text
inputPathsMap :: Maybe (HashMap Text Text)
$sel:inputTemplate:InputTransformer' :: InputTransformer -> Text
$sel:inputPathsMap:InputTransformer' :: InputTransformer -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"InputPathsMap" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
inputPathsMap,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"InputTemplate" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
inputTemplate)
          ]
      )