{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:id:Channel' :: Maybe Text
id = forall a. Maybe a
Prelude.Nothing,
      $sel:eventPublishers:Channel' :: NonEmpty EventPublisher
eventPublishers =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced 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 :: Lens' Channel (Maybe Text)
channel_id = 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 :: Lens' Channel (NonEmpty EventPublisher)
channel_eventPublishers = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: Lens' Channel Text
channel_uri = 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 Data.FromJSON Channel where
  parseJSON :: Value -> Parser Channel
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Channel"
      ( \Object
x ->
          Maybe Text -> NonEmpty EventPublisher -> Text -> Channel
Channel'
            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
"id")
            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
"eventPublishers")
            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
"uri")
      )

instance Prelude.Hashable Channel where
  hashWithSalt :: Int -> Channel -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty EventPublisher
eventPublishers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
uri

instance Prelude.NFData Channel where
  rnf :: Channel -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty EventPublisher
eventPublishers
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
uri

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"id" 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 Text
id,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"eventPublishers" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty EventPublisher
eventPublishers),
            forall a. a -> Maybe a
Prelude.Just (Key
"uri" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
uri)
          ]
      )