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

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.Attribute
import qualified Amazonka.Lens as Lens
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
(InputDefinition -> InputDefinition -> Bool)
-> (InputDefinition -> InputDefinition -> Bool)
-> Eq InputDefinition
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]
(Int -> ReadS InputDefinition)
-> ReadS [InputDefinition]
-> ReadPrec InputDefinition
-> ReadPrec [InputDefinition]
-> Read 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
(Int -> InputDefinition -> ShowS)
-> (InputDefinition -> String)
-> ([InputDefinition] -> ShowS)
-> Show InputDefinition
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. InputDefinition -> Rep InputDefinition x)
-> (forall x. Rep InputDefinition x -> InputDefinition)
-> Generic InputDefinition
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' :: NonEmpty Attribute -> InputDefinition
InputDefinition'
    { $sel:attributes:InputDefinition' :: NonEmpty Attribute
attributes =
        Tagged (NonEmpty Attribute) (Identity (NonEmpty Attribute))
-> Tagged (NonEmpty Attribute) (Identity (NonEmpty Attribute))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Attribute) (Identity (NonEmpty Attribute))
 -> Tagged (NonEmpty Attribute) (Identity (NonEmpty Attribute)))
-> NonEmpty Attribute -> NonEmpty Attribute
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 :: (NonEmpty Attribute -> f (NonEmpty Attribute))
-> InputDefinition -> f InputDefinition
inputDefinition_attributes = (InputDefinition -> NonEmpty Attribute)
-> (InputDefinition -> NonEmpty Attribute -> InputDefinition)
-> Lens
     InputDefinition
     InputDefinition
     (NonEmpty Attribute)
     (NonEmpty Attribute)
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) ((NonEmpty Attribute -> f (NonEmpty Attribute))
 -> InputDefinition -> f InputDefinition)
-> ((NonEmpty Attribute -> f (NonEmpty Attribute))
    -> NonEmpty Attribute -> f (NonEmpty Attribute))
-> (NonEmpty Attribute -> f (NonEmpty Attribute))
-> InputDefinition
-> f InputDefinition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Attribute -> f (NonEmpty Attribute))
-> NonEmpty Attribute -> f (NonEmpty Attribute)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON InputDefinition where
  parseJSON :: Value -> Parser InputDefinition
parseJSON =
    String
-> (Object -> Parser InputDefinition)
-> Value
-> Parser InputDefinition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InputDefinition"
      ( \Object
x ->
          NonEmpty Attribute -> InputDefinition
InputDefinition'
            (NonEmpty Attribute -> InputDefinition)
-> Parser (NonEmpty Attribute) -> Parser InputDefinition
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty Attribute)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"attributes")
      )

instance Prelude.Hashable InputDefinition

instance Prelude.NFData InputDefinition

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