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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A wrapper type for the attributes of an Amazon SNS subscription.
--
-- /See:/ 'newSubscription' smart constructor.
data Subscription = Subscription'
  { -- | The subscription\'s protocol.
    Subscription -> Maybe Text
protocol :: Prelude.Maybe Prelude.Text,
    -- | The subscription\'s owner.
    Subscription -> Maybe Text
owner :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the subscription\'s topic.
    Subscription -> Maybe Text
topicArn :: Prelude.Maybe Prelude.Text,
    -- | The subscription\'s endpoint (format depends on the protocol).
    Subscription -> Maybe Text
endpoint :: Prelude.Maybe Prelude.Text,
    -- | The subscription\'s ARN.
    Subscription -> Maybe Text
subscriptionArn :: Prelude.Maybe Prelude.Text
  }
  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:
--
-- 'protocol', 'subscription_protocol' - The subscription\'s protocol.
--
-- 'owner', 'subscription_owner' - The subscription\'s owner.
--
-- 'topicArn', 'subscription_topicArn' - The ARN of the subscription\'s topic.
--
-- 'endpoint', 'subscription_endpoint' - The subscription\'s endpoint (format depends on the protocol).
--
-- 'subscriptionArn', 'subscription_subscriptionArn' - The subscription\'s ARN.
newSubscription ::
  Subscription
newSubscription :: Subscription
newSubscription =
  Subscription' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Subscription
Subscription'
    { $sel:protocol:Subscription' :: Maybe Text
protocol = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:owner:Subscription' :: Maybe Text
owner = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:topicArn:Subscription' :: Maybe Text
topicArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:endpoint:Subscription' :: Maybe Text
endpoint = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:subscriptionArn:Subscription' :: Maybe Text
subscriptionArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The subscription\'s protocol.
subscription_protocol :: Lens.Lens' Subscription (Prelude.Maybe Prelude.Text)
subscription_protocol :: (Maybe Text -> f (Maybe Text)) -> Subscription -> f Subscription
subscription_protocol = (Subscription -> Maybe Text)
-> (Subscription -> Maybe Text -> Subscription)
-> Lens Subscription Subscription (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Maybe Text
protocol :: Maybe Text
$sel:protocol:Subscription' :: Subscription -> Maybe Text
protocol} -> Maybe Text
protocol) (\s :: Subscription
s@Subscription' {} Maybe Text
a -> Subscription
s {$sel:protocol:Subscription' :: Maybe Text
protocol = Maybe Text
a} :: Subscription)

-- | The subscription\'s owner.
subscription_owner :: Lens.Lens' Subscription (Prelude.Maybe Prelude.Text)
subscription_owner :: (Maybe Text -> f (Maybe Text)) -> Subscription -> f Subscription
subscription_owner = (Subscription -> Maybe Text)
-> (Subscription -> Maybe Text -> Subscription)
-> Lens Subscription Subscription (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Maybe Text
owner :: Maybe Text
$sel:owner:Subscription' :: Subscription -> Maybe Text
owner} -> Maybe Text
owner) (\s :: Subscription
s@Subscription' {} Maybe Text
a -> Subscription
s {$sel:owner:Subscription' :: Maybe Text
owner = Maybe Text
a} :: Subscription)

-- | The ARN of the subscription\'s topic.
subscription_topicArn :: Lens.Lens' Subscription (Prelude.Maybe Prelude.Text)
subscription_topicArn :: (Maybe Text -> f (Maybe Text)) -> Subscription -> f Subscription
subscription_topicArn = (Subscription -> Maybe Text)
-> (Subscription -> Maybe Text -> Subscription)
-> Lens Subscription Subscription (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Maybe Text
topicArn :: Maybe Text
$sel:topicArn:Subscription' :: Subscription -> Maybe Text
topicArn} -> Maybe Text
topicArn) (\s :: Subscription
s@Subscription' {} Maybe Text
a -> Subscription
s {$sel:topicArn:Subscription' :: Maybe Text
topicArn = Maybe Text
a} :: Subscription)

-- | The subscription\'s endpoint (format depends on the protocol).
subscription_endpoint :: Lens.Lens' Subscription (Prelude.Maybe Prelude.Text)
subscription_endpoint :: (Maybe Text -> f (Maybe Text)) -> Subscription -> f Subscription
subscription_endpoint = (Subscription -> Maybe Text)
-> (Subscription -> Maybe Text -> Subscription)
-> Lens Subscription Subscription (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Maybe Text
endpoint :: Maybe Text
$sel:endpoint:Subscription' :: Subscription -> Maybe Text
endpoint} -> Maybe Text
endpoint) (\s :: Subscription
s@Subscription' {} Maybe Text
a -> Subscription
s {$sel:endpoint:Subscription' :: Maybe Text
endpoint = Maybe Text
a} :: Subscription)

-- | The subscription\'s ARN.
subscription_subscriptionArn :: Lens.Lens' Subscription (Prelude.Maybe Prelude.Text)
subscription_subscriptionArn :: (Maybe Text -> f (Maybe Text)) -> Subscription -> f Subscription
subscription_subscriptionArn = (Subscription -> Maybe Text)
-> (Subscription -> Maybe Text -> Subscription)
-> Lens Subscription Subscription (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Maybe Text
subscriptionArn :: Maybe Text
$sel:subscriptionArn:Subscription' :: Subscription -> Maybe Text
subscriptionArn} -> Maybe Text
subscriptionArn) (\s :: Subscription
s@Subscription' {} Maybe Text
a -> Subscription
s {$sel:subscriptionArn:Subscription' :: Maybe Text
subscriptionArn = Maybe Text
a} :: Subscription)

instance Core.FromXML Subscription where
  parseXML :: [Node] -> Either String Subscription
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Subscription
Subscription'
      (Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Subscription)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe Text -> Maybe Text -> Maybe Text -> Subscription)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Protocol")
      Either
  String
  (Maybe Text
   -> Maybe Text -> Maybe Text -> Maybe Text -> Subscription)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Maybe Text -> Maybe Text -> Subscription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Owner")
      Either
  String (Maybe Text -> Maybe Text -> Maybe Text -> Subscription)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Maybe Text -> Subscription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"TopicArn")
      Either String (Maybe Text -> Maybe Text -> Subscription)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Subscription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Endpoint")
      Either String (Maybe Text -> Subscription)
-> Either String (Maybe Text) -> Either String Subscription
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"SubscriptionArn")

instance Prelude.Hashable Subscription

instance Prelude.NFData Subscription