{-# 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.IoT.Types.IotSiteWiseAction
-- 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.IoT.Types.IotSiteWiseAction where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.PutAssetPropertyValueEntry
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes an action to send data from an MQTT message that triggered the
-- rule to IoT SiteWise asset properties.
--
-- /See:/ 'newIotSiteWiseAction' smart constructor.
data IotSiteWiseAction = IotSiteWiseAction'
  { -- | A list of asset property value entries.
    IotSiteWiseAction -> NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries :: Prelude.NonEmpty PutAssetPropertyValueEntry,
    -- | The ARN of the role that grants IoT permission to send an asset property
    -- value to IoT SiteWise.
    -- (@\"Action\": \"iotsitewise:BatchPutAssetPropertyValue\"@). The trust
    -- policy can restrict access to specific asset hierarchy paths.
    IotSiteWiseAction -> Text
roleArn :: Prelude.Text
  }
  deriving (IotSiteWiseAction -> IotSiteWiseAction -> Bool
(IotSiteWiseAction -> IotSiteWiseAction -> Bool)
-> (IotSiteWiseAction -> IotSiteWiseAction -> Bool)
-> Eq IotSiteWiseAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IotSiteWiseAction -> IotSiteWiseAction -> Bool
$c/= :: IotSiteWiseAction -> IotSiteWiseAction -> Bool
== :: IotSiteWiseAction -> IotSiteWiseAction -> Bool
$c== :: IotSiteWiseAction -> IotSiteWiseAction -> Bool
Prelude.Eq, ReadPrec [IotSiteWiseAction]
ReadPrec IotSiteWiseAction
Int -> ReadS IotSiteWiseAction
ReadS [IotSiteWiseAction]
(Int -> ReadS IotSiteWiseAction)
-> ReadS [IotSiteWiseAction]
-> ReadPrec IotSiteWiseAction
-> ReadPrec [IotSiteWiseAction]
-> Read IotSiteWiseAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IotSiteWiseAction]
$creadListPrec :: ReadPrec [IotSiteWiseAction]
readPrec :: ReadPrec IotSiteWiseAction
$creadPrec :: ReadPrec IotSiteWiseAction
readList :: ReadS [IotSiteWiseAction]
$creadList :: ReadS [IotSiteWiseAction]
readsPrec :: Int -> ReadS IotSiteWiseAction
$creadsPrec :: Int -> ReadS IotSiteWiseAction
Prelude.Read, Int -> IotSiteWiseAction -> ShowS
[IotSiteWiseAction] -> ShowS
IotSiteWiseAction -> String
(Int -> IotSiteWiseAction -> ShowS)
-> (IotSiteWiseAction -> String)
-> ([IotSiteWiseAction] -> ShowS)
-> Show IotSiteWiseAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IotSiteWiseAction] -> ShowS
$cshowList :: [IotSiteWiseAction] -> ShowS
show :: IotSiteWiseAction -> String
$cshow :: IotSiteWiseAction -> String
showsPrec :: Int -> IotSiteWiseAction -> ShowS
$cshowsPrec :: Int -> IotSiteWiseAction -> ShowS
Prelude.Show, (forall x. IotSiteWiseAction -> Rep IotSiteWiseAction x)
-> (forall x. Rep IotSiteWiseAction x -> IotSiteWiseAction)
-> Generic IotSiteWiseAction
forall x. Rep IotSiteWiseAction x -> IotSiteWiseAction
forall x. IotSiteWiseAction -> Rep IotSiteWiseAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IotSiteWiseAction x -> IotSiteWiseAction
$cfrom :: forall x. IotSiteWiseAction -> Rep IotSiteWiseAction x
Prelude.Generic)

-- |
-- Create a value of 'IotSiteWiseAction' 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:
--
-- 'putAssetPropertyValueEntries', 'iotSiteWiseAction_putAssetPropertyValueEntries' - A list of asset property value entries.
--
-- 'roleArn', 'iotSiteWiseAction_roleArn' - The ARN of the role that grants IoT permission to send an asset property
-- value to IoT SiteWise.
-- (@\"Action\": \"iotsitewise:BatchPutAssetPropertyValue\"@). The trust
-- policy can restrict access to specific asset hierarchy paths.
newIotSiteWiseAction ::
  -- | 'putAssetPropertyValueEntries'
  Prelude.NonEmpty PutAssetPropertyValueEntry ->
  -- | 'roleArn'
  Prelude.Text ->
  IotSiteWiseAction
newIotSiteWiseAction :: NonEmpty PutAssetPropertyValueEntry -> Text -> IotSiteWiseAction
newIotSiteWiseAction
  NonEmpty PutAssetPropertyValueEntry
pPutAssetPropertyValueEntries_
  Text
pRoleArn_ =
    IotSiteWiseAction' :: NonEmpty PutAssetPropertyValueEntry -> Text -> IotSiteWiseAction
IotSiteWiseAction'
      { $sel:putAssetPropertyValueEntries:IotSiteWiseAction' :: NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries =
          Tagged
  (NonEmpty PutAssetPropertyValueEntry)
  (Identity (NonEmpty PutAssetPropertyValueEntry))
-> Tagged
     (NonEmpty PutAssetPropertyValueEntry)
     (Identity (NonEmpty PutAssetPropertyValueEntry))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty PutAssetPropertyValueEntry)
   (Identity (NonEmpty PutAssetPropertyValueEntry))
 -> Tagged
      (NonEmpty PutAssetPropertyValueEntry)
      (Identity (NonEmpty PutAssetPropertyValueEntry)))
-> NonEmpty PutAssetPropertyValueEntry
-> NonEmpty PutAssetPropertyValueEntry
forall t b. AReview t b -> b -> t
Lens.# NonEmpty PutAssetPropertyValueEntry
pPutAssetPropertyValueEntries_,
        $sel:roleArn:IotSiteWiseAction' :: Text
roleArn = Text
pRoleArn_
      }

-- | A list of asset property value entries.
iotSiteWiseAction_putAssetPropertyValueEntries :: Lens.Lens' IotSiteWiseAction (Prelude.NonEmpty PutAssetPropertyValueEntry)
iotSiteWiseAction_putAssetPropertyValueEntries :: (NonEmpty PutAssetPropertyValueEntry
 -> f (NonEmpty PutAssetPropertyValueEntry))
-> IotSiteWiseAction -> f IotSiteWiseAction
iotSiteWiseAction_putAssetPropertyValueEntries = (IotSiteWiseAction -> NonEmpty PutAssetPropertyValueEntry)
-> (IotSiteWiseAction
    -> NonEmpty PutAssetPropertyValueEntry -> IotSiteWiseAction)
-> Lens
     IotSiteWiseAction
     IotSiteWiseAction
     (NonEmpty PutAssetPropertyValueEntry)
     (NonEmpty PutAssetPropertyValueEntry)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotSiteWiseAction' {NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries :: NonEmpty PutAssetPropertyValueEntry
$sel:putAssetPropertyValueEntries:IotSiteWiseAction' :: IotSiteWiseAction -> NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries} -> NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries) (\s :: IotSiteWiseAction
s@IotSiteWiseAction' {} NonEmpty PutAssetPropertyValueEntry
a -> IotSiteWiseAction
s {$sel:putAssetPropertyValueEntries:IotSiteWiseAction' :: NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries = NonEmpty PutAssetPropertyValueEntry
a} :: IotSiteWiseAction) ((NonEmpty PutAssetPropertyValueEntry
  -> f (NonEmpty PutAssetPropertyValueEntry))
 -> IotSiteWiseAction -> f IotSiteWiseAction)
-> ((NonEmpty PutAssetPropertyValueEntry
     -> f (NonEmpty PutAssetPropertyValueEntry))
    -> NonEmpty PutAssetPropertyValueEntry
    -> f (NonEmpty PutAssetPropertyValueEntry))
-> (NonEmpty PutAssetPropertyValueEntry
    -> f (NonEmpty PutAssetPropertyValueEntry))
-> IotSiteWiseAction
-> f IotSiteWiseAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty PutAssetPropertyValueEntry
 -> f (NonEmpty PutAssetPropertyValueEntry))
-> NonEmpty PutAssetPropertyValueEntry
-> f (NonEmpty PutAssetPropertyValueEntry)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ARN of the role that grants IoT permission to send an asset property
-- value to IoT SiteWise.
-- (@\"Action\": \"iotsitewise:BatchPutAssetPropertyValue\"@). The trust
-- policy can restrict access to specific asset hierarchy paths.
iotSiteWiseAction_roleArn :: Lens.Lens' IotSiteWiseAction Prelude.Text
iotSiteWiseAction_roleArn :: (Text -> f Text) -> IotSiteWiseAction -> f IotSiteWiseAction
iotSiteWiseAction_roleArn = (IotSiteWiseAction -> Text)
-> (IotSiteWiseAction -> Text -> IotSiteWiseAction)
-> Lens IotSiteWiseAction IotSiteWiseAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IotSiteWiseAction' {Text
roleArn :: Text
$sel:roleArn:IotSiteWiseAction' :: IotSiteWiseAction -> Text
roleArn} -> Text
roleArn) (\s :: IotSiteWiseAction
s@IotSiteWiseAction' {} Text
a -> IotSiteWiseAction
s {$sel:roleArn:IotSiteWiseAction' :: Text
roleArn = Text
a} :: IotSiteWiseAction)

instance Core.FromJSON IotSiteWiseAction where
  parseJSON :: Value -> Parser IotSiteWiseAction
parseJSON =
    String
-> (Object -> Parser IotSiteWiseAction)
-> Value
-> Parser IotSiteWiseAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IotSiteWiseAction"
      ( \Object
x ->
          NonEmpty PutAssetPropertyValueEntry -> Text -> IotSiteWiseAction
IotSiteWiseAction'
            (NonEmpty PutAssetPropertyValueEntry -> Text -> IotSiteWiseAction)
-> Parser (NonEmpty PutAssetPropertyValueEntry)
-> Parser (Text -> IotSiteWiseAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty PutAssetPropertyValueEntry)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"putAssetPropertyValueEntries")
            Parser (Text -> IotSiteWiseAction)
-> Parser Text -> Parser IotSiteWiseAction
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
"roleArn")
      )

instance Prelude.Hashable IotSiteWiseAction

instance Prelude.NFData IotSiteWiseAction

instance Core.ToJSON IotSiteWiseAction where
  toJSON :: IotSiteWiseAction -> Value
toJSON IotSiteWiseAction' {NonEmpty PutAssetPropertyValueEntry
Text
roleArn :: Text
putAssetPropertyValueEntries :: NonEmpty PutAssetPropertyValueEntry
$sel:roleArn:IotSiteWiseAction' :: IotSiteWiseAction -> Text
$sel:putAssetPropertyValueEntries:IotSiteWiseAction' :: IotSiteWiseAction -> NonEmpty PutAssetPropertyValueEntry
..} =
    [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
"putAssetPropertyValueEntries"
                  Text -> NonEmpty PutAssetPropertyValueEntry -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty PutAssetPropertyValueEntry
putAssetPropertyValueEntries
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn)
          ]
      )