{-# 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.ChangePassword
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Changes the password for a specified user in a user pool.
module Amazonka.CognitoIdentityProvider.ChangePassword
  ( -- * Creating a Request
    ChangePassword (..),
    newChangePassword,

    -- * Request Lenses
    changePassword_previousPassword,
    changePassword_proposedPassword,
    changePassword_accessToken,

    -- * Destructuring the Response
    ChangePasswordResponse (..),
    newChangePasswordResponse,

    -- * Response Lenses
    changePasswordResponse_httpStatus,
  )
where

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

-- | Represents the request to change a user password.
--
-- /See:/ 'newChangePassword' smart constructor.
data ChangePassword = ChangePassword'
  { -- | The old password.
    ChangePassword -> Sensitive Text
previousPassword :: Data.Sensitive Prelude.Text,
    -- | The new password.
    ChangePassword -> Sensitive Text
proposedPassword :: Data.Sensitive Prelude.Text,
    -- | A valid access token that Amazon Cognito issued to the user whose
    -- password you want to change.
    ChangePassword -> Sensitive Text
accessToken :: Data.Sensitive Prelude.Text
  }
  deriving (ChangePassword -> ChangePassword -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChangePassword -> ChangePassword -> Bool
$c/= :: ChangePassword -> ChangePassword -> Bool
== :: ChangePassword -> ChangePassword -> Bool
$c== :: ChangePassword -> ChangePassword -> Bool
Prelude.Eq, Int -> ChangePassword -> ShowS
[ChangePassword] -> ShowS
ChangePassword -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChangePassword] -> ShowS
$cshowList :: [ChangePassword] -> ShowS
show :: ChangePassword -> String
$cshow :: ChangePassword -> String
showsPrec :: Int -> ChangePassword -> ShowS
$cshowsPrec :: Int -> ChangePassword -> ShowS
Prelude.Show, forall x. Rep ChangePassword x -> ChangePassword
forall x. ChangePassword -> Rep ChangePassword x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ChangePassword x -> ChangePassword
$cfrom :: forall x. ChangePassword -> Rep ChangePassword x
Prelude.Generic)

-- |
-- Create a value of 'ChangePassword' 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:
--
-- 'previousPassword', 'changePassword_previousPassword' - The old password.
--
-- 'proposedPassword', 'changePassword_proposedPassword' - The new password.
--
-- 'accessToken', 'changePassword_accessToken' - A valid access token that Amazon Cognito issued to the user whose
-- password you want to change.
newChangePassword ::
  -- | 'previousPassword'
  Prelude.Text ->
  -- | 'proposedPassword'
  Prelude.Text ->
  -- | 'accessToken'
  Prelude.Text ->
  ChangePassword
newChangePassword :: Text -> Text -> Text -> ChangePassword
newChangePassword
  Text
pPreviousPassword_
  Text
pProposedPassword_
  Text
pAccessToken_ =
    ChangePassword'
      { $sel:previousPassword:ChangePassword' :: Sensitive Text
previousPassword =
          forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pPreviousPassword_,
        $sel:proposedPassword:ChangePassword' :: Sensitive Text
proposedPassword =
          forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pProposedPassword_,
        $sel:accessToken:ChangePassword' :: Sensitive Text
accessToken = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pAccessToken_
      }

-- | The old password.
changePassword_previousPassword :: Lens.Lens' ChangePassword Prelude.Text
changePassword_previousPassword :: Lens' ChangePassword Text
changePassword_previousPassword = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangePassword' {Sensitive Text
previousPassword :: Sensitive Text
$sel:previousPassword:ChangePassword' :: ChangePassword -> Sensitive Text
previousPassword} -> Sensitive Text
previousPassword) (\s :: ChangePassword
s@ChangePassword' {} Sensitive Text
a -> ChangePassword
s {$sel:previousPassword:ChangePassword' :: Sensitive Text
previousPassword = Sensitive Text
a} :: ChangePassword) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The new password.
changePassword_proposedPassword :: Lens.Lens' ChangePassword Prelude.Text
changePassword_proposedPassword :: Lens' ChangePassword Text
changePassword_proposedPassword = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangePassword' {Sensitive Text
proposedPassword :: Sensitive Text
$sel:proposedPassword:ChangePassword' :: ChangePassword -> Sensitive Text
proposedPassword} -> Sensitive Text
proposedPassword) (\s :: ChangePassword
s@ChangePassword' {} Sensitive Text
a -> ChangePassword
s {$sel:proposedPassword:ChangePassword' :: Sensitive Text
proposedPassword = Sensitive Text
a} :: ChangePassword) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | A valid access token that Amazon Cognito issued to the user whose
-- password you want to change.
changePassword_accessToken :: Lens.Lens' ChangePassword Prelude.Text
changePassword_accessToken :: Lens' ChangePassword Text
changePassword_accessToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ChangePassword' {Sensitive Text
accessToken :: Sensitive Text
$sel:accessToken:ChangePassword' :: ChangePassword -> Sensitive Text
accessToken} -> Sensitive Text
accessToken) (\s :: ChangePassword
s@ChangePassword' {} Sensitive Text
a -> ChangePassword
s {$sel:accessToken:ChangePassword' :: Sensitive Text
accessToken = Sensitive Text
a} :: ChangePassword) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Core.AWSRequest ChangePassword where
  type
    AWSResponse ChangePassword =
      ChangePasswordResponse
  request :: (Service -> Service) -> ChangePassword -> Request ChangePassword
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 ChangePassword
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ChangePassword)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> ChangePasswordResponse
ChangePasswordResponse'
            forall (f :: * -> *) a b. Functor 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 ChangePassword where
  hashWithSalt :: Int -> ChangePassword -> Int
hashWithSalt Int
_salt ChangePassword' {Sensitive Text
accessToken :: Sensitive Text
proposedPassword :: Sensitive Text
previousPassword :: Sensitive Text
$sel:accessToken:ChangePassword' :: ChangePassword -> Sensitive Text
$sel:proposedPassword:ChangePassword' :: ChangePassword -> Sensitive Text
$sel:previousPassword:ChangePassword' :: ChangePassword -> Sensitive Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
previousPassword
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
proposedPassword
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
accessToken

instance Prelude.NFData ChangePassword where
  rnf :: ChangePassword -> ()
rnf ChangePassword' {Sensitive Text
accessToken :: Sensitive Text
proposedPassword :: Sensitive Text
previousPassword :: Sensitive Text
$sel:accessToken:ChangePassword' :: ChangePassword -> Sensitive Text
$sel:proposedPassword:ChangePassword' :: ChangePassword -> Sensitive Text
$sel:previousPassword:ChangePassword' :: ChangePassword -> Sensitive Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
previousPassword
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
proposedPassword
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
accessToken

instance Data.ToHeaders ChangePassword where
  toHeaders :: ChangePassword -> 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
"AWSCognitoIdentityProviderService.ChangePassword" ::
                          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 ChangePassword where
  toJSON :: ChangePassword -> Value
toJSON ChangePassword' {Sensitive Text
accessToken :: Sensitive Text
proposedPassword :: Sensitive Text
previousPassword :: Sensitive Text
$sel:accessToken:ChangePassword' :: ChangePassword -> Sensitive Text
$sel:proposedPassword:ChangePassword' :: ChangePassword -> Sensitive Text
$sel:previousPassword:ChangePassword' :: ChangePassword -> Sensitive Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"PreviousPassword" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
previousPassword),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ProposedPassword" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
proposedPassword),
            forall a. a -> Maybe a
Prelude.Just (Key
"AccessToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
accessToken)
          ]
      )

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

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

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

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

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

instance Prelude.NFData ChangePasswordResponse where
  rnf :: ChangePasswordResponse -> ()
rnf ChangePasswordResponse' {Int
httpStatus :: Int
$sel:httpStatus:ChangePasswordResponse' :: ChangePasswordResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus