{-# 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.CognitoIdentityProvider.VerifyUserAttribute
-- 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)
--
-- Verifies the specified user attributes in the user pool.
module Amazonka.CognitoIdentityProvider.VerifyUserAttribute
  ( -- * Creating a Request
    VerifyUserAttribute (..),
    newVerifyUserAttribute,

    -- * Request Lenses
    verifyUserAttribute_accessToken,
    verifyUserAttribute_attributeName,
    verifyUserAttribute_code,

    -- * Destructuring the Response
    VerifyUserAttributeResponse (..),
    newVerifyUserAttributeResponse,

    -- * Response Lenses
    verifyUserAttributeResponse_httpStatus,
  )
where

import Amazonka.CognitoIdentityProvider.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

-- | Represents the request to verify user attributes.
--
-- /See:/ 'newVerifyUserAttribute' smart constructor.
data VerifyUserAttribute = VerifyUserAttribute'
  { -- | Represents the access token of the request to verify user attributes.
    VerifyUserAttribute -> Sensitive Text
accessToken :: Core.Sensitive Prelude.Text,
    -- | The attribute name in the request to verify user attributes.
    VerifyUserAttribute -> Text
attributeName :: Prelude.Text,
    -- | The verification code in the request to verify user attributes.
    VerifyUserAttribute -> Text
code :: Prelude.Text
  }
  deriving (VerifyUserAttribute -> VerifyUserAttribute -> Bool
(VerifyUserAttribute -> VerifyUserAttribute -> Bool)
-> (VerifyUserAttribute -> VerifyUserAttribute -> Bool)
-> Eq VerifyUserAttribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VerifyUserAttribute -> VerifyUserAttribute -> Bool
$c/= :: VerifyUserAttribute -> VerifyUserAttribute -> Bool
== :: VerifyUserAttribute -> VerifyUserAttribute -> Bool
$c== :: VerifyUserAttribute -> VerifyUserAttribute -> Bool
Prelude.Eq, Int -> VerifyUserAttribute -> ShowS
[VerifyUserAttribute] -> ShowS
VerifyUserAttribute -> String
(Int -> VerifyUserAttribute -> ShowS)
-> (VerifyUserAttribute -> String)
-> ([VerifyUserAttribute] -> ShowS)
-> Show VerifyUserAttribute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerifyUserAttribute] -> ShowS
$cshowList :: [VerifyUserAttribute] -> ShowS
show :: VerifyUserAttribute -> String
$cshow :: VerifyUserAttribute -> String
showsPrec :: Int -> VerifyUserAttribute -> ShowS
$cshowsPrec :: Int -> VerifyUserAttribute -> ShowS
Prelude.Show, (forall x. VerifyUserAttribute -> Rep VerifyUserAttribute x)
-> (forall x. Rep VerifyUserAttribute x -> VerifyUserAttribute)
-> Generic VerifyUserAttribute
forall x. Rep VerifyUserAttribute x -> VerifyUserAttribute
forall x. VerifyUserAttribute -> Rep VerifyUserAttribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VerifyUserAttribute x -> VerifyUserAttribute
$cfrom :: forall x. VerifyUserAttribute -> Rep VerifyUserAttribute x
Prelude.Generic)

-- |
-- Create a value of 'VerifyUserAttribute' 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:
--
-- 'accessToken', 'verifyUserAttribute_accessToken' - Represents the access token of the request to verify user attributes.
--
-- 'attributeName', 'verifyUserAttribute_attributeName' - The attribute name in the request to verify user attributes.
--
-- 'code', 'verifyUserAttribute_code' - The verification code in the request to verify user attributes.
newVerifyUserAttribute ::
  -- | 'accessToken'
  Prelude.Text ->
  -- | 'attributeName'
  Prelude.Text ->
  -- | 'code'
  Prelude.Text ->
  VerifyUserAttribute
newVerifyUserAttribute :: Text -> Text -> Text -> VerifyUserAttribute
newVerifyUserAttribute
  Text
pAccessToken_
  Text
pAttributeName_
  Text
pCode_ =
    VerifyUserAttribute' :: Sensitive Text -> Text -> Text -> VerifyUserAttribute
VerifyUserAttribute'
      { $sel:accessToken:VerifyUserAttribute' :: Sensitive Text
accessToken =
          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
pAccessToken_,
        $sel:attributeName:VerifyUserAttribute' :: Text
attributeName = Text
pAttributeName_,
        $sel:code:VerifyUserAttribute' :: Text
code = Text
pCode_
      }

-- | Represents the access token of the request to verify user attributes.
verifyUserAttribute_accessToken :: Lens.Lens' VerifyUserAttribute Prelude.Text
verifyUserAttribute_accessToken :: (Text -> f Text) -> VerifyUserAttribute -> f VerifyUserAttribute
verifyUserAttribute_accessToken = (VerifyUserAttribute -> Sensitive Text)
-> (VerifyUserAttribute -> Sensitive Text -> VerifyUserAttribute)
-> Lens
     VerifyUserAttribute
     VerifyUserAttribute
     (Sensitive Text)
     (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VerifyUserAttribute' {Sensitive Text
accessToken :: Sensitive Text
$sel:accessToken:VerifyUserAttribute' :: VerifyUserAttribute -> Sensitive Text
accessToken} -> Sensitive Text
accessToken) (\s :: VerifyUserAttribute
s@VerifyUserAttribute' {} Sensitive Text
a -> VerifyUserAttribute
s {$sel:accessToken:VerifyUserAttribute' :: Sensitive Text
accessToken = Sensitive Text
a} :: VerifyUserAttribute) ((Sensitive Text -> f (Sensitive Text))
 -> VerifyUserAttribute -> f VerifyUserAttribute)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> VerifyUserAttribute
-> f VerifyUserAttribute
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

-- | The attribute name in the request to verify user attributes.
verifyUserAttribute_attributeName :: Lens.Lens' VerifyUserAttribute Prelude.Text
verifyUserAttribute_attributeName :: (Text -> f Text) -> VerifyUserAttribute -> f VerifyUserAttribute
verifyUserAttribute_attributeName = (VerifyUserAttribute -> Text)
-> (VerifyUserAttribute -> Text -> VerifyUserAttribute)
-> Lens VerifyUserAttribute VerifyUserAttribute Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VerifyUserAttribute' {Text
attributeName :: Text
$sel:attributeName:VerifyUserAttribute' :: VerifyUserAttribute -> Text
attributeName} -> Text
attributeName) (\s :: VerifyUserAttribute
s@VerifyUserAttribute' {} Text
a -> VerifyUserAttribute
s {$sel:attributeName:VerifyUserAttribute' :: Text
attributeName = Text
a} :: VerifyUserAttribute)

-- | The verification code in the request to verify user attributes.
verifyUserAttribute_code :: Lens.Lens' VerifyUserAttribute Prelude.Text
verifyUserAttribute_code :: (Text -> f Text) -> VerifyUserAttribute -> f VerifyUserAttribute
verifyUserAttribute_code = (VerifyUserAttribute -> Text)
-> (VerifyUserAttribute -> Text -> VerifyUserAttribute)
-> Lens VerifyUserAttribute VerifyUserAttribute Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VerifyUserAttribute' {Text
code :: Text
$sel:code:VerifyUserAttribute' :: VerifyUserAttribute -> Text
code} -> Text
code) (\s :: VerifyUserAttribute
s@VerifyUserAttribute' {} Text
a -> VerifyUserAttribute
s {$sel:code:VerifyUserAttribute' :: Text
code = Text
a} :: VerifyUserAttribute)

instance Core.AWSRequest VerifyUserAttribute where
  type
    AWSResponse VerifyUserAttribute =
      VerifyUserAttributeResponse
  request :: VerifyUserAttribute -> Request VerifyUserAttribute
request = Service -> VerifyUserAttribute -> Request VerifyUserAttribute
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy VerifyUserAttribute
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse VerifyUserAttribute)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse VerifyUserAttribute))
-> Logger
-> Service
-> Proxy VerifyUserAttribute
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse VerifyUserAttribute)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> VerifyUserAttributeResponse
VerifyUserAttributeResponse'
            (Int -> VerifyUserAttributeResponse)
-> Either String Int -> Either String VerifyUserAttributeResponse
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))
      )

instance Prelude.Hashable VerifyUserAttribute

instance Prelude.NFData VerifyUserAttribute

instance Core.ToHeaders VerifyUserAttribute where
  toHeaders :: VerifyUserAttribute -> ResponseHeaders
toHeaders =
    ResponseHeaders -> VerifyUserAttribute -> 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
"AWSCognitoIdentityProviderService.VerifyUserAttribute" ::
                          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 VerifyUserAttribute where
  toJSON :: VerifyUserAttribute -> Value
toJSON VerifyUserAttribute' {Text
Sensitive Text
code :: Text
attributeName :: Text
accessToken :: Sensitive Text
$sel:code:VerifyUserAttribute' :: VerifyUserAttribute -> Text
$sel:attributeName:VerifyUserAttribute' :: VerifyUserAttribute -> Text
$sel:accessToken:VerifyUserAttribute' :: VerifyUserAttribute -> Sensitive 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
"AccessToken" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
accessToken),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"AttributeName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
attributeName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Code" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
code)
          ]
      )

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

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

-- | A container representing the response from the server from the request
-- to verify user attributes.
--
-- /See:/ 'newVerifyUserAttributeResponse' smart constructor.
data VerifyUserAttributeResponse = VerifyUserAttributeResponse'
  { -- | The response's http status code.
    VerifyUserAttributeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (VerifyUserAttributeResponse -> VerifyUserAttributeResponse -> Bool
(VerifyUserAttributeResponse
 -> VerifyUserAttributeResponse -> Bool)
-> (VerifyUserAttributeResponse
    -> VerifyUserAttributeResponse -> Bool)
-> Eq VerifyUserAttributeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VerifyUserAttributeResponse -> VerifyUserAttributeResponse -> Bool
$c/= :: VerifyUserAttributeResponse -> VerifyUserAttributeResponse -> Bool
== :: VerifyUserAttributeResponse -> VerifyUserAttributeResponse -> Bool
$c== :: VerifyUserAttributeResponse -> VerifyUserAttributeResponse -> Bool
Prelude.Eq, ReadPrec [VerifyUserAttributeResponse]
ReadPrec VerifyUserAttributeResponse
Int -> ReadS VerifyUserAttributeResponse
ReadS [VerifyUserAttributeResponse]
(Int -> ReadS VerifyUserAttributeResponse)
-> ReadS [VerifyUserAttributeResponse]
-> ReadPrec VerifyUserAttributeResponse
-> ReadPrec [VerifyUserAttributeResponse]
-> Read VerifyUserAttributeResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VerifyUserAttributeResponse]
$creadListPrec :: ReadPrec [VerifyUserAttributeResponse]
readPrec :: ReadPrec VerifyUserAttributeResponse
$creadPrec :: ReadPrec VerifyUserAttributeResponse
readList :: ReadS [VerifyUserAttributeResponse]
$creadList :: ReadS [VerifyUserAttributeResponse]
readsPrec :: Int -> ReadS VerifyUserAttributeResponse
$creadsPrec :: Int -> ReadS VerifyUserAttributeResponse
Prelude.Read, Int -> VerifyUserAttributeResponse -> ShowS
[VerifyUserAttributeResponse] -> ShowS
VerifyUserAttributeResponse -> String
(Int -> VerifyUserAttributeResponse -> ShowS)
-> (VerifyUserAttributeResponse -> String)
-> ([VerifyUserAttributeResponse] -> ShowS)
-> Show VerifyUserAttributeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerifyUserAttributeResponse] -> ShowS
$cshowList :: [VerifyUserAttributeResponse] -> ShowS
show :: VerifyUserAttributeResponse -> String
$cshow :: VerifyUserAttributeResponse -> String
showsPrec :: Int -> VerifyUserAttributeResponse -> ShowS
$cshowsPrec :: Int -> VerifyUserAttributeResponse -> ShowS
Prelude.Show, (forall x.
 VerifyUserAttributeResponse -> Rep VerifyUserAttributeResponse x)
-> (forall x.
    Rep VerifyUserAttributeResponse x -> VerifyUserAttributeResponse)
-> Generic VerifyUserAttributeResponse
forall x.
Rep VerifyUserAttributeResponse x -> VerifyUserAttributeResponse
forall x.
VerifyUserAttributeResponse -> Rep VerifyUserAttributeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep VerifyUserAttributeResponse x -> VerifyUserAttributeResponse
$cfrom :: forall x.
VerifyUserAttributeResponse -> Rep VerifyUserAttributeResponse x
Prelude.Generic)

-- |
-- Create a value of 'VerifyUserAttributeResponse' 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', 'verifyUserAttributeResponse_httpStatus' - The response's http status code.
newVerifyUserAttributeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  VerifyUserAttributeResponse
newVerifyUserAttributeResponse :: Int -> VerifyUserAttributeResponse
newVerifyUserAttributeResponse Int
pHttpStatus_ =
  VerifyUserAttributeResponse' :: Int -> VerifyUserAttributeResponse
VerifyUserAttributeResponse'
    { $sel:httpStatus:VerifyUserAttributeResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData VerifyUserAttributeResponse