{-# 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.CodeGuruProfiler.Types.Channel
-- 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.CodeGuruProfiler.Types.Channel where

import Amazonka.CodeGuruProfiler.Types.EventPublisher
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Notification medium for users to get alerted for events that occur in
-- application profile. We support SNS topic as a notification channel.
--
-- /See:/ 'newChannel' smart constructor.
data Channel = Channel'
  { -- | Unique identifier for each @Channel@ in the notification configuration
    -- of a Profiling Group. A random UUID for channelId is used when adding a
    -- channel to the notification configuration if not specified in the
    -- request.
    Channel -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | List of publishers for different type of events that may be detected in
    -- an application from the profile. Anomaly detection is the only event
    -- publisher in Profiler.
    Channel -> NonEmpty EventPublisher
eventPublishers :: Prelude.NonEmpty EventPublisher,
    -- | Unique arn of the resource to be used for notifications. We support a
    -- valid SNS topic arn as a channel uri.
    Channel -> Text
uri :: Prelude.Text
  }
  deriving (Channel -> Channel -> Bool
(Channel -> Channel -> Bool)
-> (Channel -> Channel -> Bool) -> Eq Channel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Channel -> Channel -> Bool
$c/= :: Channel -> Channel -> Bool
== :: Channel -> Channel -> Bool
$c== :: Channel -> Channel -> Bool
Prelude.Eq, ReadPrec [Channel]
ReadPrec Channel
Int -> ReadS Channel
ReadS [Channel]
(Int -> ReadS Channel)
-> ReadS [Channel]
-> ReadPrec Channel
-> ReadPrec [Channel]
-> Read Channel
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Channel]
$creadListPrec :: ReadPrec [Channel]
readPrec :: ReadPrec Channel
$creadPrec :: ReadPrec Channel
readList :: ReadS [Channel]
$creadList :: ReadS [Channel]
readsPrec :: Int -> ReadS Channel
$creadsPrec :: Int -> ReadS Channel
Prelude.Read, Int -> Channel -> ShowS
[Channel] -> ShowS
Channel -> String
(Int -> Channel -> ShowS)
-> (Channel -> String) -> ([Channel] -> ShowS) -> Show Channel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Channel] -> ShowS
$cshowList :: [Channel] -> ShowS
show :: Channel -> String
$cshow :: Channel -> String
showsPrec :: Int -> Channel -> ShowS
$cshowsPrec :: Int -> Channel -> ShowS
Prelude.Show, (forall x. Channel -> Rep Channel x)
-> (forall x. Rep Channel x -> Channel) -> Generic Channel
forall x. Rep Channel x -> Channel
forall x. Channel -> Rep Channel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Channel x -> Channel
$cfrom :: forall x. Channel -> Rep Channel x
Prelude.Generic)

-- |
-- Create a value of 'Channel' 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:
--
-- 'id', 'channel_id' - Unique identifier for each @Channel@ in the notification configuration
-- of a Profiling Group. A random UUID for channelId is used when adding a
-- channel to the notification configuration if not specified in the
-- request.
--
-- 'eventPublishers', 'channel_eventPublishers' - List of publishers for different type of events that may be detected in
-- an application from the profile. Anomaly detection is the only event
-- publisher in Profiler.
--
-- 'uri', 'channel_uri' - Unique arn of the resource to be used for notifications. We support a
-- valid SNS topic arn as a channel uri.
newChannel ::
  -- | 'eventPublishers'
  Prelude.NonEmpty EventPublisher ->
  -- | 'uri'
  Prelude.Text ->
  Channel
newChannel :: NonEmpty EventPublisher -> Text -> Channel
newChannel NonEmpty EventPublisher
pEventPublishers_ Text
pUri_ =
  Channel' :: Maybe Text -> NonEmpty EventPublisher -> Text -> Channel
Channel'
    { $sel:id:Channel' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventPublishers:Channel' :: NonEmpty EventPublisher
eventPublishers =
        Tagged
  (NonEmpty EventPublisher) (Identity (NonEmpty EventPublisher))
-> Tagged
     (NonEmpty EventPublisher) (Identity (NonEmpty EventPublisher))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty EventPublisher) (Identity (NonEmpty EventPublisher))
 -> Tagged
      (NonEmpty EventPublisher) (Identity (NonEmpty EventPublisher)))
-> NonEmpty EventPublisher -> NonEmpty EventPublisher
forall t b. AReview t b -> b -> t
Lens.# NonEmpty EventPublisher
pEventPublishers_,
      $sel:uri:Channel' :: Text
uri = Text
pUri_
    }

-- | Unique identifier for each @Channel@ in the notification configuration
-- of a Profiling Group. A random UUID for channelId is used when adding a
-- channel to the notification configuration if not specified in the
-- request.
channel_id :: Lens.Lens' Channel (Prelude.Maybe Prelude.Text)
channel_id :: (Maybe Text -> f (Maybe Text)) -> Channel -> f Channel
channel_id = (Channel -> Maybe Text)
-> (Channel -> Maybe Text -> Channel)
-> Lens Channel Channel (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Maybe Text
id :: Maybe Text
$sel:id:Channel' :: Channel -> Maybe Text
id} -> Maybe Text
id) (\s :: Channel
s@Channel' {} Maybe Text
a -> Channel
s {$sel:id:Channel' :: Maybe Text
id = Maybe Text
a} :: Channel)

-- | List of publishers for different type of events that may be detected in
-- an application from the profile. Anomaly detection is the only event
-- publisher in Profiler.
channel_eventPublishers :: Lens.Lens' Channel (Prelude.NonEmpty EventPublisher)
channel_eventPublishers :: (NonEmpty EventPublisher -> f (NonEmpty EventPublisher))
-> Channel -> f Channel
channel_eventPublishers = (Channel -> NonEmpty EventPublisher)
-> (Channel -> NonEmpty EventPublisher -> Channel)
-> Lens
     Channel Channel (NonEmpty EventPublisher) (NonEmpty EventPublisher)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {NonEmpty EventPublisher
eventPublishers :: NonEmpty EventPublisher
$sel:eventPublishers:Channel' :: Channel -> NonEmpty EventPublisher
eventPublishers} -> NonEmpty EventPublisher
eventPublishers) (\s :: Channel
s@Channel' {} NonEmpty EventPublisher
a -> Channel
s {$sel:eventPublishers:Channel' :: NonEmpty EventPublisher
eventPublishers = NonEmpty EventPublisher
a} :: Channel) ((NonEmpty EventPublisher -> f (NonEmpty EventPublisher))
 -> Channel -> f Channel)
-> ((NonEmpty EventPublisher -> f (NonEmpty EventPublisher))
    -> NonEmpty EventPublisher -> f (NonEmpty EventPublisher))
-> (NonEmpty EventPublisher -> f (NonEmpty EventPublisher))
-> Channel
-> f Channel
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty EventPublisher -> f (NonEmpty EventPublisher))
-> NonEmpty EventPublisher -> f (NonEmpty EventPublisher)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Unique arn of the resource to be used for notifications. We support a
-- valid SNS topic arn as a channel uri.
channel_uri :: Lens.Lens' Channel Prelude.Text
channel_uri :: (Text -> f Text) -> Channel -> f Channel
channel_uri = (Channel -> Text)
-> (Channel -> Text -> Channel) -> Lens Channel Channel Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Channel' {Text
uri :: Text
$sel:uri:Channel' :: Channel -> Text
uri} -> Text
uri) (\s :: Channel
s@Channel' {} Text
a -> Channel
s {$sel:uri:Channel' :: Text
uri = Text
a} :: Channel)

instance Core.FromJSON Channel where
  parseJSON :: Value -> Parser Channel
parseJSON =
    String -> (Object -> Parser Channel) -> Value -> Parser Channel
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Channel"
      ( \Object
x ->
          Maybe Text -> NonEmpty EventPublisher -> Text -> Channel
Channel'
            (Maybe Text -> NonEmpty EventPublisher -> Text -> Channel)
-> Parser (Maybe Text)
-> Parser (NonEmpty EventPublisher -> Text -> Channel)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"id")
            Parser (NonEmpty EventPublisher -> Text -> Channel)
-> Parser (NonEmpty EventPublisher) -> Parser (Text -> Channel)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty EventPublisher)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"eventPublishers")
            Parser (Text -> Channel) -> Parser Text -> Parser Channel
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
"uri")
      )

instance Prelude.Hashable Channel

instance Prelude.NFData Channel

instance Core.ToJSON Channel where
  toJSON :: Channel -> Value
toJSON Channel' {Maybe Text
NonEmpty EventPublisher
Text
uri :: Text
eventPublishers :: NonEmpty EventPublisher
id :: Maybe Text
$sel:uri:Channel' :: Channel -> Text
$sel:eventPublishers:Channel' :: Channel -> NonEmpty EventPublisher
$sel:id:Channel' :: Channel -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
id,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"eventPublishers" Text -> NonEmpty EventPublisher -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty EventPublisher
eventPublishers),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"uri" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
uri)
          ]
      )