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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Inspector.Types.EventSubscription
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
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]
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
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. 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'
      { $sel:resourceArn:Subscription' :: Text
resourceArn = Text
pResourceArn_,
        $sel:topicArn:Subscription' :: Text
topicArn = Text
pTopicArn_,
        $sel:eventSubscriptions:Subscription' :: NonEmpty EventSubscription
eventSubscriptions =
          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 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 :: Lens' Subscription Text
subscription_resourceArn = 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 :: Lens' Subscription Text
subscription_topicArn = 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 :: Lens' Subscription (NonEmpty EventSubscription)
subscription_eventSubscriptions = 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) 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

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

instance Prelude.Hashable Subscription where
  hashWithSalt :: Int -> Subscription -> Int
hashWithSalt Int
_salt Subscription' {NonEmpty EventSubscription
Text
eventSubscriptions :: NonEmpty EventSubscription
topicArn :: Text
resourceArn :: Text
$sel:eventSubscriptions:Subscription' :: Subscription -> NonEmpty EventSubscription
$sel:topicArn:Subscription' :: Subscription -> Text
$sel:resourceArn:Subscription' :: Subscription -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
topicArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty EventSubscription
eventSubscriptions

instance Prelude.NFData Subscription where
  rnf :: Subscription -> ()
rnf Subscription' {NonEmpty EventSubscription
Text
eventSubscriptions :: NonEmpty EventSubscription
topicArn :: Text
resourceArn :: Text
$sel:eventSubscriptions:Subscription' :: Subscription -> NonEmpty EventSubscription
$sel:topicArn:Subscription' :: Subscription -> Text
$sel:resourceArn:Subscription' :: Subscription -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
resourceArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
topicArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty EventSubscription
eventSubscriptions