{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.LookoutMetrics.Types.SNSConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LookoutMetrics.Types.SnsFormat
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 format of the SNS topic.
    --
    -- -   @JSON@ – Send JSON alerts with an anomaly ID and a link to the
    --     anomaly detail page. This is the default.
    --
    -- -   @LONG_TEXT@ – Send human-readable alerts with information about the
    --     impacted timeseries and a link to the anomaly detail page. We
    --     recommend this for email.
    --
    -- -   @SHORT_TEXT@ – Send human-readable alerts with a link to the anomaly
    --     detail page. We recommend this for SMS.
    SNSConfiguration -> Maybe SnsFormat
snsFormat :: Prelude.Maybe SnsFormat,
    -- | 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
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]
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
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. 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:
--
-- 'snsFormat', 'sNSConfiguration_snsFormat' - The format of the SNS topic.
--
-- -   @JSON@ – Send JSON alerts with an anomaly ID and a link to the
--     anomaly detail page. This is the default.
--
-- -   @LONG_TEXT@ – Send human-readable alerts with information about the
--     impacted timeseries and a link to the anomaly detail page. We
--     recommend this for email.
--
-- -   @SHORT_TEXT@ – Send human-readable alerts with a link to the anomaly
--     detail page. We recommend this for SMS.
--
-- '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'
    { $sel:snsFormat:SNSConfiguration' :: Maybe SnsFormat
snsFormat = forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:SNSConfiguration' :: Text
roleArn = Text
pRoleArn_,
      $sel:snsTopicArn:SNSConfiguration' :: Text
snsTopicArn = Text
pSnsTopicArn_
    }

-- | The format of the SNS topic.
--
-- -   @JSON@ – Send JSON alerts with an anomaly ID and a link to the
--     anomaly detail page. This is the default.
--
-- -   @LONG_TEXT@ – Send human-readable alerts with information about the
--     impacted timeseries and a link to the anomaly detail page. We
--     recommend this for email.
--
-- -   @SHORT_TEXT@ – Send human-readable alerts with a link to the anomaly
--     detail page. We recommend this for SMS.
sNSConfiguration_snsFormat :: Lens.Lens' SNSConfiguration (Prelude.Maybe SnsFormat)
sNSConfiguration_snsFormat :: Lens' SNSConfiguration (Maybe SnsFormat)
sNSConfiguration_snsFormat = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SNSConfiguration' {Maybe SnsFormat
snsFormat :: Maybe SnsFormat
$sel:snsFormat:SNSConfiguration' :: SNSConfiguration -> Maybe SnsFormat
snsFormat} -> Maybe SnsFormat
snsFormat) (\s :: SNSConfiguration
s@SNSConfiguration' {} Maybe SnsFormat
a -> SNSConfiguration
s {$sel:snsFormat:SNSConfiguration' :: Maybe SnsFormat
snsFormat = Maybe SnsFormat
a} :: SNSConfiguration)

-- | The ARN of the IAM role that has access to the target SNS topic.
sNSConfiguration_roleArn :: Lens.Lens' SNSConfiguration Prelude.Text
sNSConfiguration_roleArn :: Lens' SNSConfiguration Text
sNSConfiguration_roleArn = 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 :: Lens' SNSConfiguration Text
sNSConfiguration_snsTopicArn = 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 Data.FromJSON SNSConfiguration where
  parseJSON :: Value -> Parser SNSConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SNSConfiguration"
      ( \Object
x ->
          Maybe SnsFormat -> Text -> Text -> SNSConfiguration
SNSConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"SnsFormat")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"RoleArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"SnsTopicArn")
      )

instance Prelude.Hashable SNSConfiguration where
  hashWithSalt :: Int -> SNSConfiguration -> Int
hashWithSalt Int
_salt SNSConfiguration' {Maybe SnsFormat
Text
snsTopicArn :: Text
roleArn :: Text
snsFormat :: Maybe SnsFormat
$sel:snsTopicArn:SNSConfiguration' :: SNSConfiguration -> Text
$sel:roleArn:SNSConfiguration' :: SNSConfiguration -> Text
$sel:snsFormat:SNSConfiguration' :: SNSConfiguration -> Maybe SnsFormat
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SnsFormat
snsFormat
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
snsTopicArn

instance Prelude.NFData SNSConfiguration where
  rnf :: SNSConfiguration -> ()
rnf SNSConfiguration' {Maybe SnsFormat
Text
snsTopicArn :: Text
roleArn :: Text
snsFormat :: Maybe SnsFormat
$sel:snsTopicArn:SNSConfiguration' :: SNSConfiguration -> Text
$sel:roleArn:SNSConfiguration' :: SNSConfiguration -> Text
$sel:snsFormat:SNSConfiguration' :: SNSConfiguration -> Maybe SnsFormat
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe SnsFormat
snsFormat
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
roleArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
snsTopicArn

instance Data.ToJSON SNSConfiguration where
  toJSON :: SNSConfiguration -> Value
toJSON SNSConfiguration' {Maybe SnsFormat
Text
snsTopicArn :: Text
roleArn :: Text
snsFormat :: Maybe SnsFormat
$sel:snsTopicArn:SNSConfiguration' :: SNSConfiguration -> Text
$sel:roleArn:SNSConfiguration' :: SNSConfiguration -> Text
$sel:snsFormat:SNSConfiguration' :: SNSConfiguration -> Maybe SnsFormat
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"SnsFormat" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SnsFormat
snsFormat,
            forall a. a -> Maybe a
Prelude.Just (Key
"RoleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
roleArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"SnsTopicArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
snsTopicArn)
          ]
      )