{-# 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.Inspector.Types.Subscription
-- 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.Inspector.Types.Subscription where

import qualified Amazonka.Core as Core
import Amazonka.Inspector.Types.EventSubscription
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | This data type is used as a response element in the
-- ListEventSubscriptions action.
--
-- /See:/ 'newSubscription' smart constructor.
data Subscription = Subscription'
  { -- | The ARN of the assessment template that is used during the event for
    -- which the SNS notification is sent.
    Subscription -> Text
resourceArn :: Prelude.Text,
    -- | The ARN of the Amazon Simple Notification Service (SNS) topic to which
    -- the SNS notifications are sent.
    Subscription -> Text
topicArn :: Prelude.Text,
    -- | The list of existing event subscriptions.
    Subscription -> NonEmpty EventSubscription
eventSubscriptions :: Prelude.NonEmpty EventSubscription
  }
  deriving (Subscription -> Subscription -> Bool
(Subscription -> Subscription -> Bool)
-> (Subscription -> Subscription -> Bool) -> Eq Subscription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Subscription -> Subscription -> Bool
$c/= :: Subscription -> Subscription -> Bool
== :: Subscription -> Subscription -> Bool
$c== :: Subscription -> Subscription -> Bool
Prelude.Eq, ReadPrec [Subscription]
ReadPrec Subscription
Int -> ReadS Subscription
ReadS [Subscription]
(Int -> ReadS Subscription)
-> ReadS [Subscription]
-> ReadPrec Subscription
-> ReadPrec [Subscription]
-> Read Subscription
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Subscription]
$creadListPrec :: ReadPrec [Subscription]
readPrec :: ReadPrec Subscription
$creadPrec :: ReadPrec Subscription
readList :: ReadS [Subscription]
$creadList :: ReadS [Subscription]
readsPrec :: Int -> ReadS Subscription
$creadsPrec :: Int -> ReadS Subscription
Prelude.Read, Int -> Subscription -> ShowS
[Subscription] -> ShowS
Subscription -> String
(Int -> Subscription -> ShowS)
-> (Subscription -> String)
-> ([Subscription] -> ShowS)
-> Show Subscription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Subscription] -> ShowS
$cshowList :: [Subscription] -> ShowS
show :: Subscription -> String
$cshow :: Subscription -> String
showsPrec :: Int -> Subscription -> ShowS
$cshowsPrec :: Int -> Subscription -> ShowS
Prelude.Show, (forall x. Subscription -> Rep Subscription x)
-> (forall x. Rep Subscription x -> Subscription)
-> Generic Subscription
forall x. Rep Subscription x -> Subscription
forall x. Subscription -> Rep Subscription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Subscription x -> Subscription
$cfrom :: forall x. Subscription -> Rep Subscription x
Prelude.Generic)

-- |
-- Create a value of 'Subscription' 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:
--
-- 'resourceArn', 'subscription_resourceArn' - The ARN of the assessment template that is used during the event for
-- which the SNS notification is sent.
--
-- 'topicArn', 'subscription_topicArn' - The ARN of the Amazon Simple Notification Service (SNS) topic to which
-- the SNS notifications are sent.
--
-- 'eventSubscriptions', 'subscription_eventSubscriptions' - The list of existing event subscriptions.
newSubscription ::
  -- | 'resourceArn'
  Prelude.Text ->
  -- | 'topicArn'
  Prelude.Text ->
  -- | 'eventSubscriptions'
  Prelude.NonEmpty EventSubscription ->
  Subscription
newSubscription :: Text -> Text -> NonEmpty EventSubscription -> Subscription
newSubscription
  Text
pResourceArn_
  Text
pTopicArn_
  NonEmpty EventSubscription
pEventSubscriptions_ =
    Subscription' :: Text -> Text -> NonEmpty EventSubscription -> Subscription
Subscription'
      { $sel:resourceArn:Subscription' :: Text
resourceArn = Text
pResourceArn_,
        $sel:topicArn:Subscription' :: Text
topicArn = Text
pTopicArn_,
        $sel:eventSubscriptions:Subscription' :: NonEmpty EventSubscription
eventSubscriptions =
          Tagged
  (NonEmpty EventSubscription)
  (Identity (NonEmpty EventSubscription))
-> Tagged
     (NonEmpty EventSubscription)
     (Identity (NonEmpty EventSubscription))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty EventSubscription)
   (Identity (NonEmpty EventSubscription))
 -> Tagged
      (NonEmpty EventSubscription)
      (Identity (NonEmpty EventSubscription)))
-> NonEmpty EventSubscription -> NonEmpty EventSubscription
forall t b. AReview t b -> b -> t
Lens.# NonEmpty EventSubscription
pEventSubscriptions_
      }

-- | The ARN of the assessment template that is used during the event for
-- which the SNS notification is sent.
subscription_resourceArn :: Lens.Lens' Subscription Prelude.Text
subscription_resourceArn :: (Text -> f Text) -> Subscription -> f Subscription
subscription_resourceArn = (Subscription -> Text)
-> (Subscription -> Text -> Subscription)
-> Lens Subscription Subscription Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Text
resourceArn :: Text
$sel:resourceArn:Subscription' :: Subscription -> Text
resourceArn} -> Text
resourceArn) (\s :: Subscription
s@Subscription' {} Text
a -> Subscription
s {$sel:resourceArn:Subscription' :: Text
resourceArn = Text
a} :: Subscription)

-- | The ARN of the Amazon Simple Notification Service (SNS) topic to which
-- the SNS notifications are sent.
subscription_topicArn :: Lens.Lens' Subscription Prelude.Text
subscription_topicArn :: (Text -> f Text) -> Subscription -> f Subscription
subscription_topicArn = (Subscription -> Text)
-> (Subscription -> Text -> Subscription)
-> Lens Subscription Subscription Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Text
topicArn :: Text
$sel:topicArn:Subscription' :: Subscription -> Text
topicArn} -> Text
topicArn) (\s :: Subscription
s@Subscription' {} Text
a -> Subscription
s {$sel:topicArn:Subscription' :: Text
topicArn = Text
a} :: Subscription)

-- | The list of existing event subscriptions.
subscription_eventSubscriptions :: Lens.Lens' Subscription (Prelude.NonEmpty EventSubscription)
subscription_eventSubscriptions :: (NonEmpty EventSubscription -> f (NonEmpty EventSubscription))
-> Subscription -> f Subscription
subscription_eventSubscriptions = (Subscription -> NonEmpty EventSubscription)
-> (Subscription -> NonEmpty EventSubscription -> Subscription)
-> Lens
     Subscription
     Subscription
     (NonEmpty EventSubscription)
     (NonEmpty EventSubscription)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {NonEmpty EventSubscription
eventSubscriptions :: NonEmpty EventSubscription
$sel:eventSubscriptions:Subscription' :: Subscription -> NonEmpty EventSubscription
eventSubscriptions} -> NonEmpty EventSubscription
eventSubscriptions) (\s :: Subscription
s@Subscription' {} NonEmpty EventSubscription
a -> Subscription
s {$sel:eventSubscriptions:Subscription' :: NonEmpty EventSubscription
eventSubscriptions = NonEmpty EventSubscription
a} :: Subscription) ((NonEmpty EventSubscription -> f (NonEmpty EventSubscription))
 -> Subscription -> f Subscription)
-> ((NonEmpty EventSubscription -> f (NonEmpty EventSubscription))
    -> NonEmpty EventSubscription -> f (NonEmpty EventSubscription))
-> (NonEmpty EventSubscription -> f (NonEmpty EventSubscription))
-> Subscription
-> f Subscription
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty EventSubscription -> f (NonEmpty EventSubscription))
-> NonEmpty EventSubscription -> f (NonEmpty EventSubscription)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Subscription where
  parseJSON :: Value -> Parser Subscription
parseJSON =
    String
-> (Object -> Parser Subscription) -> Value -> Parser Subscription
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Subscription"
      ( \Object
x ->
          Text -> Text -> NonEmpty EventSubscription -> Subscription
Subscription'
            (Text -> Text -> NonEmpty EventSubscription -> Subscription)
-> Parser Text
-> Parser (Text -> NonEmpty EventSubscription -> Subscription)
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
"resourceArn")
            Parser (Text -> NonEmpty EventSubscription -> Subscription)
-> Parser Text
-> Parser (NonEmpty EventSubscription -> Subscription)
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
"topicArn")
            Parser (NonEmpty EventSubscription -> Subscription)
-> Parser (NonEmpty EventSubscription) -> Parser Subscription
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty EventSubscription)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"eventSubscriptions")
      )

instance Prelude.Hashable Subscription

instance Prelude.NFData Subscription