{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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 :: (Service -> Service) -> GetChangeToken -> Request GetChangeToken
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetChangeToken
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetChangeToken)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> GetChangeTokenResponse
GetChangeTokenResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ChangeToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetChangeToken where
  hashWithSalt :: Int -> GetChangeToken -> Int
hashWithSalt Int
_salt GetChangeToken
_ =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ()

instance Prelude.NFData GetChangeToken where
  rnf :: GetChangeToken -> ()
rnf GetChangeToken
_ = ()

instance Data.ToHeaders GetChangeToken where
  toHeaders :: GetChangeToken -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"AWSWAF_20150824.GetChangeToken" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON GetChangeToken where
  toJSON :: GetChangeToken -> Value
toJSON = forall a b. a -> b -> a
Prelude.const (Object -> Value
Data.Object forall a. Monoid a => a
Prelude.mempty)

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

instance Data.ToQuery GetChangeToken where
  toQuery :: GetChangeToken -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:changeToken:GetChangeTokenResponse' :: Maybe Text
changeToken =
        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 :: Lens' GetChangeTokenResponse (Maybe Text)
getChangeTokenResponse_changeToken = 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 :: Lens' GetChangeTokenResponse Int
getChangeTokenResponse_httpStatus = 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 where
  rnf :: GetChangeTokenResponse -> ()
rnf GetChangeTokenResponse' {Int
Maybe Text
httpStatus :: Int
changeToken :: Maybe Text
$sel:httpStatus:GetChangeTokenResponse' :: GetChangeTokenResponse -> Int
$sel:changeToken:GetChangeTokenResponse' :: GetChangeTokenResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
changeToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus