{-# 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.WAF.GetChangeToken
-- 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)
--
-- This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- When you want to create, update, or delete AWS WAF objects, get a change
-- token and include the change token in the create, update, or delete
-- request. Change tokens ensure that your application doesn\'t submit
-- conflicting requests to AWS WAF.
--
-- Each create, update, or delete request must use a unique change token.
-- If your application submits a @GetChangeToken@ request and then submits
-- a second @GetChangeToken@ request before submitting a create, update, or
-- delete request, the second @GetChangeToken@ request returns the same
-- value as the first @GetChangeToken@ request.
--
-- When you use a change token in a create, update, or delete request, the
-- status of the change token changes to @PENDING@, which indicates that
-- AWS WAF is propagating the change to all AWS WAF servers. Use
-- @GetChangeTokenStatus@ to determine the status of your change token.
module Amazonka.WAF.GetChangeToken
  ( -- * Creating a Request
    GetChangeToken (..),
    newGetChangeToken,

    -- * Destructuring the Response
    GetChangeTokenResponse (..),
    newGetChangeTokenResponse,

    -- * Response Lenses
    getChangeTokenResponse_changeToken,
    getChangeTokenResponse_httpStatus,
  )
where

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
import Amazonka.WAF.Types

-- | /See:/ 'newGetChangeToken' smart constructor.
data GetChangeToken = GetChangeToken'
  {
  }
  deriving (GetChangeToken -> GetChangeToken -> Bool
(GetChangeToken -> GetChangeToken -> Bool)
-> (GetChangeToken -> GetChangeToken -> Bool) -> Eq GetChangeToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetChangeToken -> GetChangeToken -> Bool
$c/= :: GetChangeToken -> GetChangeToken -> Bool
== :: GetChangeToken -> GetChangeToken -> Bool
$c== :: GetChangeToken -> GetChangeToken -> Bool
Prelude.Eq, ReadPrec [GetChangeToken]
ReadPrec GetChangeToken
Int -> ReadS GetChangeToken
ReadS [GetChangeToken]
(Int -> ReadS GetChangeToken)
-> ReadS [GetChangeToken]
-> ReadPrec GetChangeToken
-> ReadPrec [GetChangeToken]
-> Read GetChangeToken
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetChangeToken]
$creadListPrec :: ReadPrec [GetChangeToken]
readPrec :: ReadPrec GetChangeToken
$creadPrec :: ReadPrec GetChangeToken
readList :: ReadS [GetChangeToken]
$creadList :: ReadS [GetChangeToken]
readsPrec :: Int -> ReadS GetChangeToken
$creadsPrec :: Int -> ReadS GetChangeToken
Prelude.Read, Int -> GetChangeToken -> ShowS
[GetChangeToken] -> ShowS
GetChangeToken -> String
(Int -> GetChangeToken -> ShowS)
-> (GetChangeToken -> String)
-> ([GetChangeToken] -> ShowS)
-> Show GetChangeToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetChangeToken] -> ShowS
$cshowList :: [GetChangeToken] -> ShowS
show :: GetChangeToken -> String
$cshow :: GetChangeToken -> String
showsPrec :: Int -> GetChangeToken -> ShowS
$cshowsPrec :: Int -> GetChangeToken -> ShowS
Prelude.Show, (forall x. GetChangeToken -> Rep GetChangeToken x)
-> (forall x. Rep GetChangeToken x -> GetChangeToken)
-> Generic GetChangeToken
forall x. Rep GetChangeToken x -> GetChangeToken
forall x. GetChangeToken -> Rep GetChangeToken x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetChangeToken x -> GetChangeToken
$cfrom :: forall x. GetChangeToken -> Rep GetChangeToken x
Prelude.Generic)

-- |
-- Create a value of 'GetChangeToken' 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.
newGetChangeToken ::
  GetChangeToken
newGetChangeToken :: GetChangeToken
newGetChangeToken = GetChangeToken
GetChangeToken'

instance Core.AWSRequest GetChangeToken where
  type
    AWSResponse GetChangeToken =
      GetChangeTokenResponse
  request :: GetChangeToken -> Request GetChangeToken
request = Service -> GetChangeToken -> Request GetChangeToken
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetChangeToken
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetChangeToken)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetChangeToken))
-> Logger
-> Service
-> Proxy GetChangeToken
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetChangeToken)))
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 ->
          Maybe Text -> Int -> GetChangeTokenResponse
GetChangeTokenResponse'
            (Maybe Text -> Int -> GetChangeTokenResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetChangeTokenResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ChangeToken")
            Either String (Int -> GetChangeTokenResponse)
-> Either String Int -> Either String GetChangeTokenResponse
forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable GetChangeToken

instance Prelude.NFData GetChangeToken

instance Core.ToHeaders GetChangeToken where
  toHeaders :: GetChangeToken -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetChangeToken -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSWAF_20150824.GetChangeToken" ::
                          Prelude.ByteString
                      ),
            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 GetChangeToken where
  toJSON :: GetChangeToken -> Value
toJSON = Value -> GetChangeToken -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

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

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

-- | /See:/ 'newGetChangeTokenResponse' smart constructor.
data GetChangeTokenResponse = GetChangeTokenResponse'
  { -- | The @ChangeToken@ that you used in the request. Use this value in a
    -- @GetChangeTokenStatus@ request to get the current status of the request.
    GetChangeTokenResponse -> Maybe Text
changeToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetChangeTokenResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetChangeTokenResponse -> GetChangeTokenResponse -> Bool
(GetChangeTokenResponse -> GetChangeTokenResponse -> Bool)
-> (GetChangeTokenResponse -> GetChangeTokenResponse -> Bool)
-> Eq GetChangeTokenResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetChangeTokenResponse -> GetChangeTokenResponse -> Bool
$c/= :: GetChangeTokenResponse -> GetChangeTokenResponse -> Bool
== :: GetChangeTokenResponse -> GetChangeTokenResponse -> Bool
$c== :: GetChangeTokenResponse -> GetChangeTokenResponse -> Bool
Prelude.Eq, ReadPrec [GetChangeTokenResponse]
ReadPrec GetChangeTokenResponse
Int -> ReadS GetChangeTokenResponse
ReadS [GetChangeTokenResponse]
(Int -> ReadS GetChangeTokenResponse)
-> ReadS [GetChangeTokenResponse]
-> ReadPrec GetChangeTokenResponse
-> ReadPrec [GetChangeTokenResponse]
-> Read GetChangeTokenResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetChangeTokenResponse]
$creadListPrec :: ReadPrec [GetChangeTokenResponse]
readPrec :: ReadPrec GetChangeTokenResponse
$creadPrec :: ReadPrec GetChangeTokenResponse
readList :: ReadS [GetChangeTokenResponse]
$creadList :: ReadS [GetChangeTokenResponse]
readsPrec :: Int -> ReadS GetChangeTokenResponse
$creadsPrec :: Int -> ReadS GetChangeTokenResponse
Prelude.Read, Int -> GetChangeTokenResponse -> ShowS
[GetChangeTokenResponse] -> ShowS
GetChangeTokenResponse -> String
(Int -> GetChangeTokenResponse -> ShowS)
-> (GetChangeTokenResponse -> String)
-> ([GetChangeTokenResponse] -> ShowS)
-> Show GetChangeTokenResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetChangeTokenResponse] -> ShowS
$cshowList :: [GetChangeTokenResponse] -> ShowS
show :: GetChangeTokenResponse -> String
$cshow :: GetChangeTokenResponse -> String
showsPrec :: Int -> GetChangeTokenResponse -> ShowS
$cshowsPrec :: Int -> GetChangeTokenResponse -> ShowS
Prelude.Show, (forall x. GetChangeTokenResponse -> Rep GetChangeTokenResponse x)
-> (forall x.
    Rep GetChangeTokenResponse x -> GetChangeTokenResponse)
-> Generic GetChangeTokenResponse
forall x. Rep GetChangeTokenResponse x -> GetChangeTokenResponse
forall x. GetChangeTokenResponse -> Rep GetChangeTokenResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetChangeTokenResponse x -> GetChangeTokenResponse
$cfrom :: forall x. GetChangeTokenResponse -> Rep GetChangeTokenResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetChangeTokenResponse' 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:
--
-- 'changeToken', 'getChangeTokenResponse_changeToken' - The @ChangeToken@ that you used in the request. Use this value in a
-- @GetChangeTokenStatus@ request to get the current status of the request.
--
-- 'httpStatus', 'getChangeTokenResponse_httpStatus' - The response's http status code.
newGetChangeTokenResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetChangeTokenResponse
newGetChangeTokenResponse :: Int -> GetChangeTokenResponse
newGetChangeTokenResponse Int
pHttpStatus_ =
  GetChangeTokenResponse' :: Maybe Text -> Int -> GetChangeTokenResponse
GetChangeTokenResponse'
    { $sel:changeToken:GetChangeTokenResponse' :: Maybe Text
changeToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetChangeTokenResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @ChangeToken@ that you used in the request. Use this value in a
-- @GetChangeTokenStatus@ request to get the current status of the request.
getChangeTokenResponse_changeToken :: Lens.Lens' GetChangeTokenResponse (Prelude.Maybe Prelude.Text)
getChangeTokenResponse_changeToken :: (Maybe Text -> f (Maybe Text))
-> GetChangeTokenResponse -> f GetChangeTokenResponse
getChangeTokenResponse_changeToken = (GetChangeTokenResponse -> Maybe Text)
-> (GetChangeTokenResponse -> Maybe Text -> GetChangeTokenResponse)
-> Lens
     GetChangeTokenResponse
     GetChangeTokenResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetChangeTokenResponse' {Maybe Text
changeToken :: Maybe Text
$sel:changeToken:GetChangeTokenResponse' :: GetChangeTokenResponse -> Maybe Text
changeToken} -> Maybe Text
changeToken) (\s :: GetChangeTokenResponse
s@GetChangeTokenResponse' {} Maybe Text
a -> GetChangeTokenResponse
s {$sel:changeToken:GetChangeTokenResponse' :: Maybe Text
changeToken = Maybe Text
a} :: GetChangeTokenResponse)

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

instance Prelude.NFData GetChangeTokenResponse