{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CodeStarNotifications.Unsubscribe
-- 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)
--
-- Removes an association between a notification rule and an Amazon SNS
-- topic so that subscribers to that topic stop receiving notifications
-- when the events described in the rule are triggered.
module Amazonka.CodeStarNotifications.Unsubscribe
  ( -- * Creating a Request
    Unsubscribe (..),
    newUnsubscribe,

    -- * Request Lenses
    unsubscribe_arn,
    unsubscribe_targetAddress,

    -- * Destructuring the Response
    UnsubscribeResponse (..),
    newUnsubscribeResponse,

    -- * Response Lenses
    unsubscribeResponse_httpStatus,
    unsubscribeResponse_arn,
  )
where

import Amazonka.CodeStarNotifications.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newUnsubscribe' smart constructor.
data Unsubscribe = Unsubscribe'
  { -- | The Amazon Resource Name (ARN) of the notification rule.
    Unsubscribe -> Text
arn :: Prelude.Text,
    -- | The ARN of the SNS topic to unsubscribe from the notification rule.
    Unsubscribe -> Sensitive Text
targetAddress :: Core.Sensitive Prelude.Text
  }
  deriving (Unsubscribe -> Unsubscribe -> Bool
(Unsubscribe -> Unsubscribe -> Bool)
-> (Unsubscribe -> Unsubscribe -> Bool) -> Eq Unsubscribe
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Unsubscribe -> Unsubscribe -> Bool
$c/= :: Unsubscribe -> Unsubscribe -> Bool
== :: Unsubscribe -> Unsubscribe -> Bool
$c== :: Unsubscribe -> Unsubscribe -> Bool
Prelude.Eq, Int -> Unsubscribe -> ShowS
[Unsubscribe] -> ShowS
Unsubscribe -> String
(Int -> Unsubscribe -> ShowS)
-> (Unsubscribe -> String)
-> ([Unsubscribe] -> ShowS)
-> Show Unsubscribe
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Unsubscribe] -> ShowS
$cshowList :: [Unsubscribe] -> ShowS
show :: Unsubscribe -> String
$cshow :: Unsubscribe -> String
showsPrec :: Int -> Unsubscribe -> ShowS
$cshowsPrec :: Int -> Unsubscribe -> ShowS
Prelude.Show, (forall x. Unsubscribe -> Rep Unsubscribe x)
-> (forall x. Rep Unsubscribe x -> Unsubscribe)
-> Generic Unsubscribe
forall x. Rep Unsubscribe x -> Unsubscribe
forall x. Unsubscribe -> Rep Unsubscribe x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Unsubscribe x -> Unsubscribe
$cfrom :: forall x. Unsubscribe -> Rep Unsubscribe x
Prelude.Generic)

-- |
-- Create a value of 'Unsubscribe' 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:
--
-- 'arn', 'unsubscribe_arn' - The Amazon Resource Name (ARN) of the notification rule.
--
-- 'targetAddress', 'unsubscribe_targetAddress' - The ARN of the SNS topic to unsubscribe from the notification rule.
newUnsubscribe ::
  -- | 'arn'
  Prelude.Text ->
  -- | 'targetAddress'
  Prelude.Text ->
  Unsubscribe
newUnsubscribe :: Text -> Text -> Unsubscribe
newUnsubscribe Text
pArn_ Text
pTargetAddress_ =
  Unsubscribe' :: Text -> Sensitive Text -> Unsubscribe
Unsubscribe'
    { $sel:arn:Unsubscribe' :: Text
arn = Text
pArn_,
      $sel:targetAddress:Unsubscribe' :: Sensitive Text
targetAddress =
        Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pTargetAddress_
    }

-- | The Amazon Resource Name (ARN) of the notification rule.
unsubscribe_arn :: Lens.Lens' Unsubscribe Prelude.Text
unsubscribe_arn :: (Text -> f Text) -> Unsubscribe -> f Unsubscribe
unsubscribe_arn = (Unsubscribe -> Text)
-> (Unsubscribe -> Text -> Unsubscribe)
-> Lens Unsubscribe Unsubscribe Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Unsubscribe' {Text
arn :: Text
$sel:arn:Unsubscribe' :: Unsubscribe -> Text
arn} -> Text
arn) (\s :: Unsubscribe
s@Unsubscribe' {} Text
a -> Unsubscribe
s {$sel:arn:Unsubscribe' :: Text
arn = Text
a} :: Unsubscribe)

-- | The ARN of the SNS topic to unsubscribe from the notification rule.
unsubscribe_targetAddress :: Lens.Lens' Unsubscribe Prelude.Text
unsubscribe_targetAddress :: (Text -> f Text) -> Unsubscribe -> f Unsubscribe
unsubscribe_targetAddress = (Unsubscribe -> Sensitive Text)
-> (Unsubscribe -> Sensitive Text -> Unsubscribe)
-> Lens Unsubscribe Unsubscribe (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Unsubscribe' {Sensitive Text
targetAddress :: Sensitive Text
$sel:targetAddress:Unsubscribe' :: Unsubscribe -> Sensitive Text
targetAddress} -> Sensitive Text
targetAddress) (\s :: Unsubscribe
s@Unsubscribe' {} Sensitive Text
a -> Unsubscribe
s {$sel:targetAddress:Unsubscribe' :: Sensitive Text
targetAddress = Sensitive Text
a} :: Unsubscribe) ((Sensitive Text -> f (Sensitive Text))
 -> Unsubscribe -> f Unsubscribe)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> Unsubscribe
-> f Unsubscribe
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Core.AWSRequest Unsubscribe where
  type AWSResponse Unsubscribe = UnsubscribeResponse
  request :: Unsubscribe -> Request Unsubscribe
request = Service -> Unsubscribe -> Request Unsubscribe
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy Unsubscribe
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Unsubscribe)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse Unsubscribe))
-> Logger
-> Service
-> Proxy Unsubscribe
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Unsubscribe)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> UnsubscribeResponse
UnsubscribeResponse'
            (Int -> Text -> UnsubscribeResponse)
-> Either String Int -> Either String (Text -> UnsubscribeResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (Text -> UnsubscribeResponse)
-> Either String Text -> Either String UnsubscribeResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"Arn")
      )

instance Prelude.Hashable Unsubscribe

instance Prelude.NFData Unsubscribe

instance Core.ToHeaders Unsubscribe where
  toHeaders :: Unsubscribe -> ResponseHeaders
toHeaders =
    ResponseHeaders -> Unsubscribe -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON Unsubscribe where
  toJSON :: Unsubscribe -> Value
toJSON Unsubscribe' {Text
Sensitive Text
targetAddress :: Sensitive Text
arn :: Text
$sel:targetAddress:Unsubscribe' :: Unsubscribe -> Sensitive Text
$sel:arn:Unsubscribe' :: Unsubscribe -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Arn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
arn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"TargetAddress" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
targetAddress)
          ]
      )

instance Core.ToPath Unsubscribe where
  toPath :: Unsubscribe -> ByteString
toPath = ByteString -> Unsubscribe -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/unsubscribe"

instance Core.ToQuery Unsubscribe where
  toQuery :: Unsubscribe -> QueryString
toQuery = QueryString -> Unsubscribe -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newUnsubscribeResponse' smart constructor.
data UnsubscribeResponse = UnsubscribeResponse'
  { -- | The response's http status code.
    UnsubscribeResponse -> Int
httpStatus :: Prelude.Int,
    -- | The Amazon Resource Name (ARN) of the the notification rule from which
    -- you have removed a subscription.
    UnsubscribeResponse -> Text
arn :: Prelude.Text
  }
  deriving (UnsubscribeResponse -> UnsubscribeResponse -> Bool
(UnsubscribeResponse -> UnsubscribeResponse -> Bool)
-> (UnsubscribeResponse -> UnsubscribeResponse -> Bool)
-> Eq UnsubscribeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnsubscribeResponse -> UnsubscribeResponse -> Bool
$c/= :: UnsubscribeResponse -> UnsubscribeResponse -> Bool
== :: UnsubscribeResponse -> UnsubscribeResponse -> Bool
$c== :: UnsubscribeResponse -> UnsubscribeResponse -> Bool
Prelude.Eq, ReadPrec [UnsubscribeResponse]
ReadPrec UnsubscribeResponse
Int -> ReadS UnsubscribeResponse
ReadS [UnsubscribeResponse]
(Int -> ReadS UnsubscribeResponse)
-> ReadS [UnsubscribeResponse]
-> ReadPrec UnsubscribeResponse
-> ReadPrec [UnsubscribeResponse]
-> Read UnsubscribeResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UnsubscribeResponse]
$creadListPrec :: ReadPrec [UnsubscribeResponse]
readPrec :: ReadPrec UnsubscribeResponse
$creadPrec :: ReadPrec UnsubscribeResponse
readList :: ReadS [UnsubscribeResponse]
$creadList :: ReadS [UnsubscribeResponse]
readsPrec :: Int -> ReadS UnsubscribeResponse
$creadsPrec :: Int -> ReadS UnsubscribeResponse
Prelude.Read, Int -> UnsubscribeResponse -> ShowS
[UnsubscribeResponse] -> ShowS
UnsubscribeResponse -> String
(Int -> UnsubscribeResponse -> ShowS)
-> (UnsubscribeResponse -> String)
-> ([UnsubscribeResponse] -> ShowS)
-> Show UnsubscribeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnsubscribeResponse] -> ShowS
$cshowList :: [UnsubscribeResponse] -> ShowS
show :: UnsubscribeResponse -> String
$cshow :: UnsubscribeResponse -> String
showsPrec :: Int -> UnsubscribeResponse -> ShowS
$cshowsPrec :: Int -> UnsubscribeResponse -> ShowS
Prelude.Show, (forall x. UnsubscribeResponse -> Rep UnsubscribeResponse x)
-> (forall x. Rep UnsubscribeResponse x -> UnsubscribeResponse)
-> Generic UnsubscribeResponse
forall x. Rep UnsubscribeResponse x -> UnsubscribeResponse
forall x. UnsubscribeResponse -> Rep UnsubscribeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UnsubscribeResponse x -> UnsubscribeResponse
$cfrom :: forall x. UnsubscribeResponse -> Rep UnsubscribeResponse x
Prelude.Generic)

-- |
-- Create a value of 'UnsubscribeResponse' 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:
--
-- 'httpStatus', 'unsubscribeResponse_httpStatus' - The response's http status code.
--
-- 'arn', 'unsubscribeResponse_arn' - The Amazon Resource Name (ARN) of the the notification rule from which
-- you have removed a subscription.
newUnsubscribeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'arn'
  Prelude.Text ->
  UnsubscribeResponse
newUnsubscribeResponse :: Int -> Text -> UnsubscribeResponse
newUnsubscribeResponse Int
pHttpStatus_ Text
pArn_ =
  UnsubscribeResponse' :: Int -> Text -> UnsubscribeResponse
UnsubscribeResponse'
    { $sel:httpStatus:UnsubscribeResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:arn:UnsubscribeResponse' :: Text
arn = Text
pArn_
    }

-- | The response's http status code.
unsubscribeResponse_httpStatus :: Lens.Lens' UnsubscribeResponse Prelude.Int
unsubscribeResponse_httpStatus :: (Int -> f Int) -> UnsubscribeResponse -> f UnsubscribeResponse
unsubscribeResponse_httpStatus = (UnsubscribeResponse -> Int)
-> (UnsubscribeResponse -> Int -> UnsubscribeResponse)
-> Lens UnsubscribeResponse UnsubscribeResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UnsubscribeResponse' {Int
httpStatus :: Int
$sel:httpStatus:UnsubscribeResponse' :: UnsubscribeResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: UnsubscribeResponse
s@UnsubscribeResponse' {} Int
a -> UnsubscribeResponse
s {$sel:httpStatus:UnsubscribeResponse' :: Int
httpStatus = Int
a} :: UnsubscribeResponse)

-- | The Amazon Resource Name (ARN) of the the notification rule from which
-- you have removed a subscription.
unsubscribeResponse_arn :: Lens.Lens' UnsubscribeResponse Prelude.Text
unsubscribeResponse_arn :: (Text -> f Text) -> UnsubscribeResponse -> f UnsubscribeResponse
unsubscribeResponse_arn = (UnsubscribeResponse -> Text)
-> (UnsubscribeResponse -> Text -> UnsubscribeResponse)
-> Lens UnsubscribeResponse UnsubscribeResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UnsubscribeResponse' {Text
arn :: Text
$sel:arn:UnsubscribeResponse' :: UnsubscribeResponse -> Text
arn} -> Text
arn) (\s :: UnsubscribeResponse
s@UnsubscribeResponse' {} Text
a -> UnsubscribeResponse
s {$sel:arn:UnsubscribeResponse' :: Text
arn = Text
a} :: UnsubscribeResponse)

instance Prelude.NFData UnsubscribeResponse