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

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

-- | Contains information about the SNS topic to which you want to send your
-- alerts and the IAM role that has access to that topic.
--
-- /See:/ 'newSNSConfiguration' smart constructor.
data SNSConfiguration = SNSConfiguration'
  { -- | The ARN of the IAM role that has access to the target SNS topic.
    SNSConfiguration -> Text
roleArn :: Prelude.Text,
    -- | The ARN of the target SNS topic.
    SNSConfiguration -> Text
snsTopicArn :: Prelude.Text
  }
  deriving (SNSConfiguration -> SNSConfiguration -> Bool
(SNSConfiguration -> SNSConfiguration -> Bool)
-> (SNSConfiguration -> SNSConfiguration -> Bool)
-> Eq SNSConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SNSConfiguration -> SNSConfiguration -> Bool
$c/= :: SNSConfiguration -> SNSConfiguration -> Bool
== :: SNSConfiguration -> SNSConfiguration -> Bool
$c== :: SNSConfiguration -> SNSConfiguration -> Bool
Prelude.Eq, ReadPrec [SNSConfiguration]
ReadPrec SNSConfiguration
Int -> ReadS SNSConfiguration
ReadS [SNSConfiguration]
(Int -> ReadS SNSConfiguration)
-> ReadS [SNSConfiguration]
-> ReadPrec SNSConfiguration
-> ReadPrec [SNSConfiguration]
-> Read SNSConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SNSConfiguration]
$creadListPrec :: ReadPrec [SNSConfiguration]
readPrec :: ReadPrec SNSConfiguration
$creadPrec :: ReadPrec SNSConfiguration
readList :: ReadS [SNSConfiguration]
$creadList :: ReadS [SNSConfiguration]
readsPrec :: Int -> ReadS SNSConfiguration
$creadsPrec :: Int -> ReadS SNSConfiguration
Prelude.Read, Int -> SNSConfiguration -> ShowS
[SNSConfiguration] -> ShowS
SNSConfiguration -> String
(Int -> SNSConfiguration -> ShowS)
-> (SNSConfiguration -> String)
-> ([SNSConfiguration] -> ShowS)
-> Show SNSConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SNSConfiguration] -> ShowS
$cshowList :: [SNSConfiguration] -> ShowS
show :: SNSConfiguration -> String
$cshow :: SNSConfiguration -> String
showsPrec :: Int -> SNSConfiguration -> ShowS
$cshowsPrec :: Int -> SNSConfiguration -> ShowS
Prelude.Show, (forall x. SNSConfiguration -> Rep SNSConfiguration x)
-> (forall x. Rep SNSConfiguration x -> SNSConfiguration)
-> Generic SNSConfiguration
forall x. Rep SNSConfiguration x -> SNSConfiguration
forall x. SNSConfiguration -> Rep SNSConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SNSConfiguration x -> SNSConfiguration
$cfrom :: forall x. SNSConfiguration -> Rep SNSConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'SNSConfiguration' 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', 'sNSConfiguration_roleArn' - The ARN of the IAM role that has access to the target SNS topic.
--
-- 'snsTopicArn', 'sNSConfiguration_snsTopicArn' - The ARN of the target SNS topic.
newSNSConfiguration ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'snsTopicArn'
  Prelude.Text ->
  SNSConfiguration
newSNSConfiguration :: Text -> Text -> SNSConfiguration
newSNSConfiguration Text
pRoleArn_ Text
pSnsTopicArn_ =
  SNSConfiguration' :: Text -> Text -> SNSConfiguration
SNSConfiguration'
    { $sel:roleArn:SNSConfiguration' :: Text
roleArn = Text
pRoleArn_,
      $sel:snsTopicArn:SNSConfiguration' :: Text
snsTopicArn = Text
pSnsTopicArn_
    }

-- | The ARN of the IAM role that has access to the target SNS topic.
sNSConfiguration_roleArn :: Lens.Lens' SNSConfiguration Prelude.Text
sNSConfiguration_roleArn :: (Text -> f Text) -> SNSConfiguration -> f SNSConfiguration
sNSConfiguration_roleArn = (SNSConfiguration -> Text)
-> (SNSConfiguration -> Text -> SNSConfiguration)
-> Lens SNSConfiguration SNSConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SNSConfiguration' {Text
roleArn :: Text
$sel:roleArn:SNSConfiguration' :: SNSConfiguration -> Text
roleArn} -> Text
roleArn) (\s :: SNSConfiguration
s@SNSConfiguration' {} Text
a -> SNSConfiguration
s {$sel:roleArn:SNSConfiguration' :: Text
roleArn = Text
a} :: SNSConfiguration)

-- | The ARN of the target SNS topic.
sNSConfiguration_snsTopicArn :: Lens.Lens' SNSConfiguration Prelude.Text
sNSConfiguration_snsTopicArn :: (Text -> f Text) -> SNSConfiguration -> f SNSConfiguration
sNSConfiguration_snsTopicArn = (SNSConfiguration -> Text)
-> (SNSConfiguration -> Text -> SNSConfiguration)
-> Lens SNSConfiguration SNSConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SNSConfiguration' {Text
snsTopicArn :: Text
$sel:snsTopicArn:SNSConfiguration' :: SNSConfiguration -> Text
snsTopicArn} -> Text
snsTopicArn) (\s :: SNSConfiguration
s@SNSConfiguration' {} Text
a -> SNSConfiguration
s {$sel:snsTopicArn:SNSConfiguration' :: Text
snsTopicArn = Text
a} :: SNSConfiguration)

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

instance Prelude.Hashable SNSConfiguration

instance Prelude.NFData SNSConfiguration

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