{-# 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.Attribute
-- 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.Attribute 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

-- | The attributes from the JSON payload that are made available by the
-- input. Inputs are derived from messages sent to the AWS IoT Events
-- system using @BatchPutMessage@. Each such message contains a JSON
-- payload. Those attributes (and their paired values) specified here are
-- available for use in the @condition@ expressions used by detectors.
--
-- /See:/ 'newAttribute' smart constructor.
data Attribute = Attribute'
  { -- | An expression that specifies an attribute-value pair in a JSON
    -- structure. Use this to specify an attribute from the JSON payload that
    -- is made available by the input. Inputs are derived from messages sent to
    -- AWS IoT Events (@BatchPutMessage@). Each such message contains a JSON
    -- payload. The attribute (and its paired value) specified here are
    -- available for use in the @condition@ expressions used by detectors.
    --
    -- Syntax: @\<field-name>.\<field-name>...@
    Attribute -> Text
jsonPath :: Prelude.Text
  }
  deriving (Attribute -> Attribute -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Attribute -> Attribute -> Bool
$c/= :: Attribute -> Attribute -> Bool
== :: Attribute -> Attribute -> Bool
$c== :: Attribute -> Attribute -> Bool
Prelude.Eq, ReadPrec [Attribute]
ReadPrec Attribute
Int -> ReadS Attribute
ReadS [Attribute]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Attribute]
$creadListPrec :: ReadPrec [Attribute]
readPrec :: ReadPrec Attribute
$creadPrec :: ReadPrec Attribute
readList :: ReadS [Attribute]
$creadList :: ReadS [Attribute]
readsPrec :: Int -> ReadS Attribute
$creadsPrec :: Int -> ReadS Attribute
Prelude.Read, Int -> Attribute -> ShowS
[Attribute] -> ShowS
Attribute -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Attribute] -> ShowS
$cshowList :: [Attribute] -> ShowS
show :: Attribute -> String
$cshow :: Attribute -> String
showsPrec :: Int -> Attribute -> ShowS
$cshowsPrec :: Int -> Attribute -> ShowS
Prelude.Show, forall x. Rep Attribute x -> Attribute
forall x. Attribute -> Rep Attribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Attribute x -> Attribute
$cfrom :: forall x. Attribute -> Rep Attribute x
Prelude.Generic)

-- |
-- Create a value of 'Attribute' 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:
--
-- 'jsonPath', 'attribute_jsonPath' - An expression that specifies an attribute-value pair in a JSON
-- structure. Use this to specify an attribute from the JSON payload that
-- is made available by the input. Inputs are derived from messages sent to
-- AWS IoT Events (@BatchPutMessage@). Each such message contains a JSON
-- payload. The attribute (and its paired value) specified here are
-- available for use in the @condition@ expressions used by detectors.
--
-- Syntax: @\<field-name>.\<field-name>...@
newAttribute ::
  -- | 'jsonPath'
  Prelude.Text ->
  Attribute
newAttribute :: Text -> Attribute
newAttribute Text
pJsonPath_ =
  Attribute' {$sel:jsonPath:Attribute' :: Text
jsonPath = Text
pJsonPath_}

-- | An expression that specifies an attribute-value pair in a JSON
-- structure. Use this to specify an attribute from the JSON payload that
-- is made available by the input. Inputs are derived from messages sent to
-- AWS IoT Events (@BatchPutMessage@). Each such message contains a JSON
-- payload. The attribute (and its paired value) specified here are
-- available for use in the @condition@ expressions used by detectors.
--
-- Syntax: @\<field-name>.\<field-name>...@
attribute_jsonPath :: Lens.Lens' Attribute Prelude.Text
attribute_jsonPath :: Lens' Attribute Text
attribute_jsonPath = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attribute' {Text
jsonPath :: Text
$sel:jsonPath:Attribute' :: Attribute -> Text
jsonPath} -> Text
jsonPath) (\s :: Attribute
s@Attribute' {} Text
a -> Attribute
s {$sel:jsonPath:Attribute' :: Text
jsonPath = Text
a} :: Attribute)

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

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

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

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