{-# 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.InputDefinition
-- 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.InputDefinition 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.Attribute
import qualified Amazonka.Prelude as Prelude

-- | The definition of the input.
--
-- /See:/ 'newInputDefinition' smart constructor.
data InputDefinition = InputDefinition'
  { -- | 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, and those attributes (and their paired values) specified here
    -- are available for use in the @condition@ expressions used by detectors
    -- that monitor this input.
    InputDefinition -> NonEmpty Attribute
attributes :: Prelude.NonEmpty Attribute
  }
  deriving (InputDefinition -> InputDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InputDefinition -> InputDefinition -> Bool
$c/= :: InputDefinition -> InputDefinition -> Bool
== :: InputDefinition -> InputDefinition -> Bool
$c== :: InputDefinition -> InputDefinition -> Bool
Prelude.Eq, ReadPrec [InputDefinition]
ReadPrec InputDefinition
Int -> ReadS InputDefinition
ReadS [InputDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InputDefinition]
$creadListPrec :: ReadPrec [InputDefinition]
readPrec :: ReadPrec InputDefinition
$creadPrec :: ReadPrec InputDefinition
readList :: ReadS [InputDefinition]
$creadList :: ReadS [InputDefinition]
readsPrec :: Int -> ReadS InputDefinition
$creadsPrec :: Int -> ReadS InputDefinition
Prelude.Read, Int -> InputDefinition -> ShowS
[InputDefinition] -> ShowS
InputDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InputDefinition] -> ShowS
$cshowList :: [InputDefinition] -> ShowS
show :: InputDefinition -> String
$cshow :: InputDefinition -> String
showsPrec :: Int -> InputDefinition -> ShowS
$cshowsPrec :: Int -> InputDefinition -> ShowS
Prelude.Show, forall x. Rep InputDefinition x -> InputDefinition
forall x. InputDefinition -> Rep InputDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InputDefinition x -> InputDefinition
$cfrom :: forall x. InputDefinition -> Rep InputDefinition x
Prelude.Generic)

-- |
-- Create a value of 'InputDefinition' 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:
--
-- 'attributes', 'inputDefinition_attributes' - 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, and those attributes (and their paired values) specified here
-- are available for use in the @condition@ expressions used by detectors
-- that monitor this input.
newInputDefinition ::
  -- | 'attributes'
  Prelude.NonEmpty Attribute ->
  InputDefinition
newInputDefinition :: NonEmpty Attribute -> InputDefinition
newInputDefinition NonEmpty Attribute
pAttributes_ =
  InputDefinition'
    { $sel:attributes:InputDefinition' :: NonEmpty Attribute
attributes =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Attribute
pAttributes_
    }

-- | 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, and those attributes (and their paired values) specified here
-- are available for use in the @condition@ expressions used by detectors
-- that monitor this input.
inputDefinition_attributes :: Lens.Lens' InputDefinition (Prelude.NonEmpty Attribute)
inputDefinition_attributes :: Lens' InputDefinition (NonEmpty Attribute)
inputDefinition_attributes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InputDefinition' {NonEmpty Attribute
attributes :: NonEmpty Attribute
$sel:attributes:InputDefinition' :: InputDefinition -> NonEmpty Attribute
attributes} -> NonEmpty Attribute
attributes) (\s :: InputDefinition
s@InputDefinition' {} NonEmpty Attribute
a -> InputDefinition
s {$sel:attributes:InputDefinition' :: NonEmpty Attribute
attributes = NonEmpty Attribute
a} :: InputDefinition) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

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

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

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