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

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

-- | Describes an action that updates a CloudWatch alarm.
--
-- /See:/ 'newCloudwatchAlarmAction' smart constructor.
data CloudwatchAlarmAction = CloudwatchAlarmAction'
  { -- | The IAM role that allows access to the CloudWatch alarm.
    CloudwatchAlarmAction -> Text
roleArn :: Prelude.Text,
    -- | The CloudWatch alarm name.
    CloudwatchAlarmAction -> Text
alarmName :: Prelude.Text,
    -- | The reason for the alarm change.
    CloudwatchAlarmAction -> Text
stateReason :: Prelude.Text,
    -- | The value of the alarm state. Acceptable values are: OK, ALARM,
    -- INSUFFICIENT_DATA.
    CloudwatchAlarmAction -> Text
stateValue :: Prelude.Text
  }
  deriving (CloudwatchAlarmAction -> CloudwatchAlarmAction -> Bool
(CloudwatchAlarmAction -> CloudwatchAlarmAction -> Bool)
-> (CloudwatchAlarmAction -> CloudwatchAlarmAction -> Bool)
-> Eq CloudwatchAlarmAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CloudwatchAlarmAction -> CloudwatchAlarmAction -> Bool
$c/= :: CloudwatchAlarmAction -> CloudwatchAlarmAction -> Bool
== :: CloudwatchAlarmAction -> CloudwatchAlarmAction -> Bool
$c== :: CloudwatchAlarmAction -> CloudwatchAlarmAction -> Bool
Prelude.Eq, ReadPrec [CloudwatchAlarmAction]
ReadPrec CloudwatchAlarmAction
Int -> ReadS CloudwatchAlarmAction
ReadS [CloudwatchAlarmAction]
(Int -> ReadS CloudwatchAlarmAction)
-> ReadS [CloudwatchAlarmAction]
-> ReadPrec CloudwatchAlarmAction
-> ReadPrec [CloudwatchAlarmAction]
-> Read CloudwatchAlarmAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CloudwatchAlarmAction]
$creadListPrec :: ReadPrec [CloudwatchAlarmAction]
readPrec :: ReadPrec CloudwatchAlarmAction
$creadPrec :: ReadPrec CloudwatchAlarmAction
readList :: ReadS [CloudwatchAlarmAction]
$creadList :: ReadS [CloudwatchAlarmAction]
readsPrec :: Int -> ReadS CloudwatchAlarmAction
$creadsPrec :: Int -> ReadS CloudwatchAlarmAction
Prelude.Read, Int -> CloudwatchAlarmAction -> ShowS
[CloudwatchAlarmAction] -> ShowS
CloudwatchAlarmAction -> String
(Int -> CloudwatchAlarmAction -> ShowS)
-> (CloudwatchAlarmAction -> String)
-> ([CloudwatchAlarmAction] -> ShowS)
-> Show CloudwatchAlarmAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CloudwatchAlarmAction] -> ShowS
$cshowList :: [CloudwatchAlarmAction] -> ShowS
show :: CloudwatchAlarmAction -> String
$cshow :: CloudwatchAlarmAction -> String
showsPrec :: Int -> CloudwatchAlarmAction -> ShowS
$cshowsPrec :: Int -> CloudwatchAlarmAction -> ShowS
Prelude.Show, (forall x. CloudwatchAlarmAction -> Rep CloudwatchAlarmAction x)
-> (forall x. Rep CloudwatchAlarmAction x -> CloudwatchAlarmAction)
-> Generic CloudwatchAlarmAction
forall x. Rep CloudwatchAlarmAction x -> CloudwatchAlarmAction
forall x. CloudwatchAlarmAction -> Rep CloudwatchAlarmAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CloudwatchAlarmAction x -> CloudwatchAlarmAction
$cfrom :: forall x. CloudwatchAlarmAction -> Rep CloudwatchAlarmAction x
Prelude.Generic)

-- |
-- Create a value of 'CloudwatchAlarmAction' 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:
--
-- 'roleArn', 'cloudwatchAlarmAction_roleArn' - The IAM role that allows access to the CloudWatch alarm.
--
-- 'alarmName', 'cloudwatchAlarmAction_alarmName' - The CloudWatch alarm name.
--
-- 'stateReason', 'cloudwatchAlarmAction_stateReason' - The reason for the alarm change.
--
-- 'stateValue', 'cloudwatchAlarmAction_stateValue' - The value of the alarm state. Acceptable values are: OK, ALARM,
-- INSUFFICIENT_DATA.
newCloudwatchAlarmAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'alarmName'
  Prelude.Text ->
  -- | 'stateReason'
  Prelude.Text ->
  -- | 'stateValue'
  Prelude.Text ->
  CloudwatchAlarmAction
newCloudwatchAlarmAction :: Text -> Text -> Text -> Text -> CloudwatchAlarmAction
newCloudwatchAlarmAction
  Text
pRoleArn_
  Text
pAlarmName_
  Text
pStateReason_
  Text
pStateValue_ =
    CloudwatchAlarmAction' :: Text -> Text -> Text -> Text -> CloudwatchAlarmAction
CloudwatchAlarmAction'
      { $sel:roleArn:CloudwatchAlarmAction' :: Text
roleArn = Text
pRoleArn_,
        $sel:alarmName:CloudwatchAlarmAction' :: Text
alarmName = Text
pAlarmName_,
        $sel:stateReason:CloudwatchAlarmAction' :: Text
stateReason = Text
pStateReason_,
        $sel:stateValue:CloudwatchAlarmAction' :: Text
stateValue = Text
pStateValue_
      }

-- | The IAM role that allows access to the CloudWatch alarm.
cloudwatchAlarmAction_roleArn :: Lens.Lens' CloudwatchAlarmAction Prelude.Text
cloudwatchAlarmAction_roleArn :: (Text -> f Text)
-> CloudwatchAlarmAction -> f CloudwatchAlarmAction
cloudwatchAlarmAction_roleArn = (CloudwatchAlarmAction -> Text)
-> (CloudwatchAlarmAction -> Text -> CloudwatchAlarmAction)
-> Lens CloudwatchAlarmAction CloudwatchAlarmAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CloudwatchAlarmAction' {Text
roleArn :: Text
$sel:roleArn:CloudwatchAlarmAction' :: CloudwatchAlarmAction -> Text
roleArn} -> Text
roleArn) (\s :: CloudwatchAlarmAction
s@CloudwatchAlarmAction' {} Text
a -> CloudwatchAlarmAction
s {$sel:roleArn:CloudwatchAlarmAction' :: Text
roleArn = Text
a} :: CloudwatchAlarmAction)

-- | The CloudWatch alarm name.
cloudwatchAlarmAction_alarmName :: Lens.Lens' CloudwatchAlarmAction Prelude.Text
cloudwatchAlarmAction_alarmName :: (Text -> f Text)
-> CloudwatchAlarmAction -> f CloudwatchAlarmAction
cloudwatchAlarmAction_alarmName = (CloudwatchAlarmAction -> Text)
-> (CloudwatchAlarmAction -> Text -> CloudwatchAlarmAction)
-> Lens CloudwatchAlarmAction CloudwatchAlarmAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CloudwatchAlarmAction' {Text
alarmName :: Text
$sel:alarmName:CloudwatchAlarmAction' :: CloudwatchAlarmAction -> Text
alarmName} -> Text
alarmName) (\s :: CloudwatchAlarmAction
s@CloudwatchAlarmAction' {} Text
a -> CloudwatchAlarmAction
s {$sel:alarmName:CloudwatchAlarmAction' :: Text
alarmName = Text
a} :: CloudwatchAlarmAction)

-- | The reason for the alarm change.
cloudwatchAlarmAction_stateReason :: Lens.Lens' CloudwatchAlarmAction Prelude.Text
cloudwatchAlarmAction_stateReason :: (Text -> f Text)
-> CloudwatchAlarmAction -> f CloudwatchAlarmAction
cloudwatchAlarmAction_stateReason = (CloudwatchAlarmAction -> Text)
-> (CloudwatchAlarmAction -> Text -> CloudwatchAlarmAction)
-> Lens CloudwatchAlarmAction CloudwatchAlarmAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CloudwatchAlarmAction' {Text
stateReason :: Text
$sel:stateReason:CloudwatchAlarmAction' :: CloudwatchAlarmAction -> Text
stateReason} -> Text
stateReason) (\s :: CloudwatchAlarmAction
s@CloudwatchAlarmAction' {} Text
a -> CloudwatchAlarmAction
s {$sel:stateReason:CloudwatchAlarmAction' :: Text
stateReason = Text
a} :: CloudwatchAlarmAction)

-- | The value of the alarm state. Acceptable values are: OK, ALARM,
-- INSUFFICIENT_DATA.
cloudwatchAlarmAction_stateValue :: Lens.Lens' CloudwatchAlarmAction Prelude.Text
cloudwatchAlarmAction_stateValue :: (Text -> f Text)
-> CloudwatchAlarmAction -> f CloudwatchAlarmAction
cloudwatchAlarmAction_stateValue = (CloudwatchAlarmAction -> Text)
-> (CloudwatchAlarmAction -> Text -> CloudwatchAlarmAction)
-> Lens CloudwatchAlarmAction CloudwatchAlarmAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CloudwatchAlarmAction' {Text
stateValue :: Text
$sel:stateValue:CloudwatchAlarmAction' :: CloudwatchAlarmAction -> Text
stateValue} -> Text
stateValue) (\s :: CloudwatchAlarmAction
s@CloudwatchAlarmAction' {} Text
a -> CloudwatchAlarmAction
s {$sel:stateValue:CloudwatchAlarmAction' :: Text
stateValue = Text
a} :: CloudwatchAlarmAction)

instance Core.FromJSON CloudwatchAlarmAction where
  parseJSON :: Value -> Parser CloudwatchAlarmAction
parseJSON =
    String
-> (Object -> Parser CloudwatchAlarmAction)
-> Value
-> Parser CloudwatchAlarmAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CloudwatchAlarmAction"
      ( \Object
x ->
          Text -> Text -> Text -> Text -> CloudwatchAlarmAction
CloudwatchAlarmAction'
            (Text -> Text -> Text -> Text -> CloudwatchAlarmAction)
-> Parser Text
-> Parser (Text -> Text -> Text -> CloudwatchAlarmAction)
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
"roleArn")
            Parser (Text -> Text -> Text -> CloudwatchAlarmAction)
-> Parser Text -> Parser (Text -> Text -> CloudwatchAlarmAction)
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
"alarmName")
            Parser (Text -> Text -> CloudwatchAlarmAction)
-> Parser Text -> Parser (Text -> CloudwatchAlarmAction)
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
"stateReason")
            Parser (Text -> CloudwatchAlarmAction)
-> Parser Text -> Parser CloudwatchAlarmAction
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
"stateValue")
      )

instance Prelude.Hashable CloudwatchAlarmAction

instance Prelude.NFData CloudwatchAlarmAction

instance Core.ToJSON CloudwatchAlarmAction where
  toJSON :: CloudwatchAlarmAction -> Value
toJSON CloudwatchAlarmAction' {Text
stateValue :: Text
stateReason :: Text
alarmName :: Text
roleArn :: Text
$sel:stateValue:CloudwatchAlarmAction' :: CloudwatchAlarmAction -> Text
$sel:stateReason:CloudwatchAlarmAction' :: CloudwatchAlarmAction -> Text
$sel:alarmName:CloudwatchAlarmAction' :: CloudwatchAlarmAction -> Text
$sel:roleArn:CloudwatchAlarmAction' :: CloudwatchAlarmAction -> 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
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"alarmName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
alarmName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"stateReason" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
stateReason),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"stateValue" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
stateValue)
          ]
      )