{-# 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.LookoutMetrics.Types.Action
-- 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.LookoutMetrics.Types.Action where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.LookoutMetrics.Types.LambdaConfiguration
import Amazonka.LookoutMetrics.Types.SNSConfiguration
import qualified Amazonka.Prelude as Prelude

-- | A configuration that specifies the action to perform when anomalies are
-- detected.
--
-- /See:/ 'newAction' smart constructor.
data Action = Action'
  { -- | A configuration for an AWS Lambda channel.
    Action -> Maybe LambdaConfiguration
lambdaConfiguration :: Prelude.Maybe LambdaConfiguration,
    -- | A configuration for an Amazon SNS channel.
    Action -> Maybe SNSConfiguration
sNSConfiguration :: Prelude.Maybe SNSConfiguration
  }
  deriving (Action -> Action -> Bool
(Action -> Action -> Bool)
-> (Action -> Action -> Bool) -> Eq Action
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Action -> Action -> Bool
$c/= :: Action -> Action -> Bool
== :: Action -> Action -> Bool
$c== :: Action -> Action -> Bool
Prelude.Eq, ReadPrec [Action]
ReadPrec Action
Int -> ReadS Action
ReadS [Action]
(Int -> ReadS Action)
-> ReadS [Action]
-> ReadPrec Action
-> ReadPrec [Action]
-> Read Action
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Action]
$creadListPrec :: ReadPrec [Action]
readPrec :: ReadPrec Action
$creadPrec :: ReadPrec Action
readList :: ReadS [Action]
$creadList :: ReadS [Action]
readsPrec :: Int -> ReadS Action
$creadsPrec :: Int -> ReadS Action
Prelude.Read, Int -> Action -> ShowS
[Action] -> ShowS
Action -> String
(Int -> Action -> ShowS)
-> (Action -> String) -> ([Action] -> ShowS) -> Show Action
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Action] -> ShowS
$cshowList :: [Action] -> ShowS
show :: Action -> String
$cshow :: Action -> String
showsPrec :: Int -> Action -> ShowS
$cshowsPrec :: Int -> Action -> ShowS
Prelude.Show, (forall x. Action -> Rep Action x)
-> (forall x. Rep Action x -> Action) -> Generic Action
forall x. Rep Action x -> Action
forall x. Action -> Rep Action x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Action x -> Action
$cfrom :: forall x. Action -> Rep Action x
Prelude.Generic)

-- |
-- Create a value of 'Action' 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:
--
-- 'lambdaConfiguration', 'action_lambdaConfiguration' - A configuration for an AWS Lambda channel.
--
-- 'sNSConfiguration', 'action_sNSConfiguration' - A configuration for an Amazon SNS channel.
newAction ::
  Action
newAction :: Action
newAction =
  Action' :: Maybe LambdaConfiguration -> Maybe SNSConfiguration -> Action
Action'
    { $sel:lambdaConfiguration:Action' :: Maybe LambdaConfiguration
lambdaConfiguration = Maybe LambdaConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:sNSConfiguration:Action' :: Maybe SNSConfiguration
sNSConfiguration = Maybe SNSConfiguration
forall a. Maybe a
Prelude.Nothing
    }

-- | A configuration for an AWS Lambda channel.
action_lambdaConfiguration :: Lens.Lens' Action (Prelude.Maybe LambdaConfiguration)
action_lambdaConfiguration :: (Maybe LambdaConfiguration -> f (Maybe LambdaConfiguration))
-> Action -> f Action
action_lambdaConfiguration = (Action -> Maybe LambdaConfiguration)
-> (Action -> Maybe LambdaConfiguration -> Action)
-> Lens
     Action
     Action
     (Maybe LambdaConfiguration)
     (Maybe LambdaConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Maybe LambdaConfiguration
lambdaConfiguration :: Maybe LambdaConfiguration
$sel:lambdaConfiguration:Action' :: Action -> Maybe LambdaConfiguration
lambdaConfiguration} -> Maybe LambdaConfiguration
lambdaConfiguration) (\s :: Action
s@Action' {} Maybe LambdaConfiguration
a -> Action
s {$sel:lambdaConfiguration:Action' :: Maybe LambdaConfiguration
lambdaConfiguration = Maybe LambdaConfiguration
a} :: Action)

-- | A configuration for an Amazon SNS channel.
action_sNSConfiguration :: Lens.Lens' Action (Prelude.Maybe SNSConfiguration)
action_sNSConfiguration :: (Maybe SNSConfiguration -> f (Maybe SNSConfiguration))
-> Action -> f Action
action_sNSConfiguration = (Action -> Maybe SNSConfiguration)
-> (Action -> Maybe SNSConfiguration -> Action)
-> Lens
     Action Action (Maybe SNSConfiguration) (Maybe SNSConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Maybe SNSConfiguration
sNSConfiguration :: Maybe SNSConfiguration
$sel:sNSConfiguration:Action' :: Action -> Maybe SNSConfiguration
sNSConfiguration} -> Maybe SNSConfiguration
sNSConfiguration) (\s :: Action
s@Action' {} Maybe SNSConfiguration
a -> Action
s {$sel:sNSConfiguration:Action' :: Maybe SNSConfiguration
sNSConfiguration = Maybe SNSConfiguration
a} :: Action)

instance Core.FromJSON Action where
  parseJSON :: Value -> Parser Action
parseJSON =
    String -> (Object -> Parser Action) -> Value -> Parser Action
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Action"
      ( \Object
x ->
          Maybe LambdaConfiguration -> Maybe SNSConfiguration -> Action
Action'
            (Maybe LambdaConfiguration -> Maybe SNSConfiguration -> Action)
-> Parser (Maybe LambdaConfiguration)
-> Parser (Maybe SNSConfiguration -> Action)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe LambdaConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"LambdaConfiguration")
            Parser (Maybe SNSConfiguration -> Action)
-> Parser (Maybe SNSConfiguration) -> Parser Action
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SNSConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SNSConfiguration")
      )

instance Prelude.Hashable Action

instance Prelude.NFData Action

instance Core.ToJSON Action where
  toJSON :: Action -> Value
toJSON Action' {Maybe LambdaConfiguration
Maybe SNSConfiguration
sNSConfiguration :: Maybe SNSConfiguration
lambdaConfiguration :: Maybe LambdaConfiguration
$sel:sNSConfiguration:Action' :: Action -> Maybe SNSConfiguration
$sel:lambdaConfiguration:Action' :: Action -> Maybe LambdaConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"LambdaConfiguration" Text -> LambdaConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (LambdaConfiguration -> Pair)
-> Maybe LambdaConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe LambdaConfiguration
lambdaConfiguration,
            (Text
"SNSConfiguration" Text -> SNSConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (SNSConfiguration -> Pair) -> Maybe SNSConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SNSConfiguration
sNSConfiguration
          ]
      )