{-# 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.SetVariableAction
-- 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.SetVariableAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about the variable and its new value.
--
-- /See:/ 'newSetVariableAction' smart constructor.
data SetVariableAction = SetVariableAction'
  { -- | The name of the variable.
    SetVariableAction -> Text
variableName :: Prelude.Text,
    -- | The new value of the variable.
    SetVariableAction -> Text
value :: Prelude.Text
  }
  deriving (SetVariableAction -> SetVariableAction -> Bool
(SetVariableAction -> SetVariableAction -> Bool)
-> (SetVariableAction -> SetVariableAction -> Bool)
-> Eq SetVariableAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetVariableAction -> SetVariableAction -> Bool
$c/= :: SetVariableAction -> SetVariableAction -> Bool
== :: SetVariableAction -> SetVariableAction -> Bool
$c== :: SetVariableAction -> SetVariableAction -> Bool
Prelude.Eq, ReadPrec [SetVariableAction]
ReadPrec SetVariableAction
Int -> ReadS SetVariableAction
ReadS [SetVariableAction]
(Int -> ReadS SetVariableAction)
-> ReadS [SetVariableAction]
-> ReadPrec SetVariableAction
-> ReadPrec [SetVariableAction]
-> Read SetVariableAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetVariableAction]
$creadListPrec :: ReadPrec [SetVariableAction]
readPrec :: ReadPrec SetVariableAction
$creadPrec :: ReadPrec SetVariableAction
readList :: ReadS [SetVariableAction]
$creadList :: ReadS [SetVariableAction]
readsPrec :: Int -> ReadS SetVariableAction
$creadsPrec :: Int -> ReadS SetVariableAction
Prelude.Read, Int -> SetVariableAction -> ShowS
[SetVariableAction] -> ShowS
SetVariableAction -> String
(Int -> SetVariableAction -> ShowS)
-> (SetVariableAction -> String)
-> ([SetVariableAction] -> ShowS)
-> Show SetVariableAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetVariableAction] -> ShowS
$cshowList :: [SetVariableAction] -> ShowS
show :: SetVariableAction -> String
$cshow :: SetVariableAction -> String
showsPrec :: Int -> SetVariableAction -> ShowS
$cshowsPrec :: Int -> SetVariableAction -> ShowS
Prelude.Show, (forall x. SetVariableAction -> Rep SetVariableAction x)
-> (forall x. Rep SetVariableAction x -> SetVariableAction)
-> Generic SetVariableAction
forall x. Rep SetVariableAction x -> SetVariableAction
forall x. SetVariableAction -> Rep SetVariableAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetVariableAction x -> SetVariableAction
$cfrom :: forall x. SetVariableAction -> Rep SetVariableAction x
Prelude.Generic)

-- |
-- Create a value of 'SetVariableAction' 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:
--
-- 'variableName', 'setVariableAction_variableName' - The name of the variable.
--
-- 'value', 'setVariableAction_value' - The new value of the variable.
newSetVariableAction ::
  -- | 'variableName'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  SetVariableAction
newSetVariableAction :: Text -> Text -> SetVariableAction
newSetVariableAction Text
pVariableName_ Text
pValue_ =
  SetVariableAction' :: Text -> Text -> SetVariableAction
SetVariableAction'
    { $sel:variableName:SetVariableAction' :: Text
variableName = Text
pVariableName_,
      $sel:value:SetVariableAction' :: Text
value = Text
pValue_
    }

-- | The name of the variable.
setVariableAction_variableName :: Lens.Lens' SetVariableAction Prelude.Text
setVariableAction_variableName :: (Text -> f Text) -> SetVariableAction -> f SetVariableAction
setVariableAction_variableName = (SetVariableAction -> Text)
-> (SetVariableAction -> Text -> SetVariableAction)
-> Lens SetVariableAction SetVariableAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetVariableAction' {Text
variableName :: Text
$sel:variableName:SetVariableAction' :: SetVariableAction -> Text
variableName} -> Text
variableName) (\s :: SetVariableAction
s@SetVariableAction' {} Text
a -> SetVariableAction
s {$sel:variableName:SetVariableAction' :: Text
variableName = Text
a} :: SetVariableAction)

-- | The new value of the variable.
setVariableAction_value :: Lens.Lens' SetVariableAction Prelude.Text
setVariableAction_value :: (Text -> f Text) -> SetVariableAction -> f SetVariableAction
setVariableAction_value = (SetVariableAction -> Text)
-> (SetVariableAction -> Text -> SetVariableAction)
-> Lens SetVariableAction SetVariableAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetVariableAction' {Text
value :: Text
$sel:value:SetVariableAction' :: SetVariableAction -> Text
value} -> Text
value) (\s :: SetVariableAction
s@SetVariableAction' {} Text
a -> SetVariableAction
s {$sel:value:SetVariableAction' :: Text
value = Text
a} :: SetVariableAction)

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

instance Prelude.Hashable SetVariableAction

instance Prelude.NFData SetVariableAction

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