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

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

-- | A structure containing the alert target ARN and the role ARN.
--
-- /See:/ 'newAlertTarget' smart constructor.
data AlertTarget = AlertTarget'
  { -- | The Amazon Resource Name (ARN) of the notification target to which
    -- alerts are sent.
    AlertTarget -> Text
alertTargetArn :: Prelude.Text,
    -- | The ARN of the role that grants permission to send alerts to the
    -- notification target.
    AlertTarget -> Text
roleArn :: Prelude.Text
  }
  deriving (AlertTarget -> AlertTarget -> Bool
(AlertTarget -> AlertTarget -> Bool)
-> (AlertTarget -> AlertTarget -> Bool) -> Eq AlertTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AlertTarget -> AlertTarget -> Bool
$c/= :: AlertTarget -> AlertTarget -> Bool
== :: AlertTarget -> AlertTarget -> Bool
$c== :: AlertTarget -> AlertTarget -> Bool
Prelude.Eq, ReadPrec [AlertTarget]
ReadPrec AlertTarget
Int -> ReadS AlertTarget
ReadS [AlertTarget]
(Int -> ReadS AlertTarget)
-> ReadS [AlertTarget]
-> ReadPrec AlertTarget
-> ReadPrec [AlertTarget]
-> Read AlertTarget
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AlertTarget]
$creadListPrec :: ReadPrec [AlertTarget]
readPrec :: ReadPrec AlertTarget
$creadPrec :: ReadPrec AlertTarget
readList :: ReadS [AlertTarget]
$creadList :: ReadS [AlertTarget]
readsPrec :: Int -> ReadS AlertTarget
$creadsPrec :: Int -> ReadS AlertTarget
Prelude.Read, Int -> AlertTarget -> ShowS
[AlertTarget] -> ShowS
AlertTarget -> String
(Int -> AlertTarget -> ShowS)
-> (AlertTarget -> String)
-> ([AlertTarget] -> ShowS)
-> Show AlertTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AlertTarget] -> ShowS
$cshowList :: [AlertTarget] -> ShowS
show :: AlertTarget -> String
$cshow :: AlertTarget -> String
showsPrec :: Int -> AlertTarget -> ShowS
$cshowsPrec :: Int -> AlertTarget -> ShowS
Prelude.Show, (forall x. AlertTarget -> Rep AlertTarget x)
-> (forall x. Rep AlertTarget x -> AlertTarget)
-> Generic AlertTarget
forall x. Rep AlertTarget x -> AlertTarget
forall x. AlertTarget -> Rep AlertTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AlertTarget x -> AlertTarget
$cfrom :: forall x. AlertTarget -> Rep AlertTarget x
Prelude.Generic)

-- |
-- Create a value of 'AlertTarget' 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:
--
-- 'alertTargetArn', 'alertTarget_alertTargetArn' - The Amazon Resource Name (ARN) of the notification target to which
-- alerts are sent.
--
-- 'roleArn', 'alertTarget_roleArn' - The ARN of the role that grants permission to send alerts to the
-- notification target.
newAlertTarget ::
  -- | 'alertTargetArn'
  Prelude.Text ->
  -- | 'roleArn'
  Prelude.Text ->
  AlertTarget
newAlertTarget :: Text -> Text -> AlertTarget
newAlertTarget Text
pAlertTargetArn_ Text
pRoleArn_ =
  AlertTarget' :: Text -> Text -> AlertTarget
AlertTarget'
    { $sel:alertTargetArn:AlertTarget' :: Text
alertTargetArn = Text
pAlertTargetArn_,
      $sel:roleArn:AlertTarget' :: Text
roleArn = Text
pRoleArn_
    }

-- | The Amazon Resource Name (ARN) of the notification target to which
-- alerts are sent.
alertTarget_alertTargetArn :: Lens.Lens' AlertTarget Prelude.Text
alertTarget_alertTargetArn :: (Text -> f Text) -> AlertTarget -> f AlertTarget
alertTarget_alertTargetArn = (AlertTarget -> Text)
-> (AlertTarget -> Text -> AlertTarget)
-> Lens AlertTarget AlertTarget Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AlertTarget' {Text
alertTargetArn :: Text
$sel:alertTargetArn:AlertTarget' :: AlertTarget -> Text
alertTargetArn} -> Text
alertTargetArn) (\s :: AlertTarget
s@AlertTarget' {} Text
a -> AlertTarget
s {$sel:alertTargetArn:AlertTarget' :: Text
alertTargetArn = Text
a} :: AlertTarget)

-- | The ARN of the role that grants permission to send alerts to the
-- notification target.
alertTarget_roleArn :: Lens.Lens' AlertTarget Prelude.Text
alertTarget_roleArn :: (Text -> f Text) -> AlertTarget -> f AlertTarget
alertTarget_roleArn = (AlertTarget -> Text)
-> (AlertTarget -> Text -> AlertTarget)
-> Lens AlertTarget AlertTarget Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AlertTarget' {Text
roleArn :: Text
$sel:roleArn:AlertTarget' :: AlertTarget -> Text
roleArn} -> Text
roleArn) (\s :: AlertTarget
s@AlertTarget' {} Text
a -> AlertTarget
s {$sel:roleArn:AlertTarget' :: Text
roleArn = Text
a} :: AlertTarget)

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

instance Prelude.NFData AlertTarget

instance Core.ToJSON AlertTarget where
  toJSON :: AlertTarget -> Value
toJSON AlertTarget' {Text
roleArn :: Text
alertTargetArn :: Text
$sel:roleArn:AlertTarget' :: AlertTarget -> Text
$sel:alertTargetArn:AlertTarget' :: AlertTarget -> 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
"alertTargetArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
alertTargetArn),
            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)
          ]
      )