{-# 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.IoTEvents.Types.Payload
-- 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.IoTEvents.Types.Payload where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTEvents.Types.PayloadType
import qualified Amazonka.Prelude as Prelude

-- | Information needed to configure the payload.
--
-- By default, AWS IoT Events generates a standard payload in JSON for any
-- action. This action payload contains all attribute-value pairs that have
-- the information about the detector model instance and the event
-- triggered the action. To configure the action payload, you can use
-- @contentExpression@.
--
-- /See:/ 'newPayload' smart constructor.
data Payload = Payload'
  { -- | The content of the payload. You can use a string expression that
    -- includes quoted strings (@\'\<string>\'@), variables
    -- (@$variable.\<variable-name>@), input values
    -- (@$input.\<input-name>.\<path-to-datum>@), string concatenations, and
    -- quoted strings that contain @${}@ as the content. The recommended
    -- maximum size of a content expression is 1 KB.
    Payload -> Text
contentExpression :: Prelude.Text,
    -- | The value of the payload type can be either @STRING@ or @JSON@.
    Payload -> PayloadType
type' :: PayloadType
  }
  deriving (Payload -> Payload -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Payload -> Payload -> Bool
$c/= :: Payload -> Payload -> Bool
== :: Payload -> Payload -> Bool
$c== :: Payload -> Payload -> Bool
Prelude.Eq, ReadPrec [Payload]
ReadPrec Payload
Int -> ReadS Payload
ReadS [Payload]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Payload]
$creadListPrec :: ReadPrec [Payload]
readPrec :: ReadPrec Payload
$creadPrec :: ReadPrec Payload
readList :: ReadS [Payload]
$creadList :: ReadS [Payload]
readsPrec :: Int -> ReadS Payload
$creadsPrec :: Int -> ReadS Payload
Prelude.Read, Int -> Payload -> ShowS
[Payload] -> ShowS
Payload -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Payload] -> ShowS
$cshowList :: [Payload] -> ShowS
show :: Payload -> String
$cshow :: Payload -> String
showsPrec :: Int -> Payload -> ShowS
$cshowsPrec :: Int -> Payload -> ShowS
Prelude.Show, forall x. Rep Payload x -> Payload
forall x. Payload -> Rep Payload x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Payload x -> Payload
$cfrom :: forall x. Payload -> Rep Payload x
Prelude.Generic)

-- |
-- Create a value of 'Payload' 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:
--
-- 'contentExpression', 'payload_contentExpression' - The content of the payload. You can use a string expression that
-- includes quoted strings (@\'\<string>\'@), variables
-- (@$variable.\<variable-name>@), input values
-- (@$input.\<input-name>.\<path-to-datum>@), string concatenations, and
-- quoted strings that contain @${}@ as the content. The recommended
-- maximum size of a content expression is 1 KB.
--
-- 'type'', 'payload_type' - The value of the payload type can be either @STRING@ or @JSON@.
newPayload ::
  -- | 'contentExpression'
  Prelude.Text ->
  -- | 'type''
  PayloadType ->
  Payload
newPayload :: Text -> PayloadType -> Payload
newPayload Text
pContentExpression_ PayloadType
pType_ =
  Payload'
    { $sel:contentExpression:Payload' :: Text
contentExpression = Text
pContentExpression_,
      $sel:type':Payload' :: PayloadType
type' = PayloadType
pType_
    }

-- | The content of the payload. You can use a string expression that
-- includes quoted strings (@\'\<string>\'@), variables
-- (@$variable.\<variable-name>@), input values
-- (@$input.\<input-name>.\<path-to-datum>@), string concatenations, and
-- quoted strings that contain @${}@ as the content. The recommended
-- maximum size of a content expression is 1 KB.
payload_contentExpression :: Lens.Lens' Payload Prelude.Text
payload_contentExpression :: Lens' Payload Text
payload_contentExpression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Payload' {Text
contentExpression :: Text
$sel:contentExpression:Payload' :: Payload -> Text
contentExpression} -> Text
contentExpression) (\s :: Payload
s@Payload' {} Text
a -> Payload
s {$sel:contentExpression:Payload' :: Text
contentExpression = Text
a} :: Payload)

-- | The value of the payload type can be either @STRING@ or @JSON@.
payload_type :: Lens.Lens' Payload PayloadType
payload_type :: Lens' Payload PayloadType
payload_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Payload' {PayloadType
type' :: PayloadType
$sel:type':Payload' :: Payload -> PayloadType
type'} -> PayloadType
type') (\s :: Payload
s@Payload' {} PayloadType
a -> Payload
s {$sel:type':Payload' :: PayloadType
type' = PayloadType
a} :: Payload)

instance Data.FromJSON Payload where
  parseJSON :: Value -> Parser Payload
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Payload"
      ( \Object
x ->
          Text -> PayloadType -> Payload
Payload'
            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
"contentExpression")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"type")
      )

instance Prelude.Hashable Payload where
  hashWithSalt :: Int -> Payload -> Int
hashWithSalt Int
_salt Payload' {Text
PayloadType
type' :: PayloadType
contentExpression :: Text
$sel:type':Payload' :: Payload -> PayloadType
$sel:contentExpression:Payload' :: Payload -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
contentExpression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PayloadType
type'

instance Prelude.NFData Payload where
  rnf :: Payload -> ()
rnf Payload' {Text
PayloadType
type' :: PayloadType
contentExpression :: Text
$sel:type':Payload' :: Payload -> PayloadType
$sel:contentExpression:Payload' :: Payload -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
contentExpression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PayloadType
type'

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