{-# 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.SetUserSettings
-- 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 action is no longer supported./ You can use it to configure only
-- SMS MFA. You can\'t use it to configure time-based one-time password
-- (TOTP) software token MFA. To configure either type of MFA, use
-- <https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_SetUserMFAPreference.html SetUserMFAPreference>
-- instead.
module Amazonka.CognitoIdentityProvider.SetUserSettings
  ( -- * Creating a Request
    SetUserSettings (..),
    newSetUserSettings,

    -- * Request Lenses
    setUserSettings_accessToken,
    setUserSettings_mfaOptions,

    -- * Destructuring the Response
    SetUserSettingsResponse (..),
    newSetUserSettingsResponse,

    -- * Response Lenses
    setUserSettingsResponse_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 set user settings.
--
-- /See:/ 'newSetUserSettings' smart constructor.
data SetUserSettings = SetUserSettings'
  { -- | A valid access token that Amazon Cognito issued to the user whose user
    -- settings you want to configure.
    SetUserSettings -> Sensitive Text
accessToken :: Data.Sensitive Prelude.Text,
    -- | You can use this parameter only to set an SMS configuration that uses
    -- SMS for delivery.
    SetUserSettings -> [MFAOptionType]
mfaOptions :: [MFAOptionType]
  }
  deriving (SetUserSettings -> SetUserSettings -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetUserSettings -> SetUserSettings -> Bool
$c/= :: SetUserSettings -> SetUserSettings -> Bool
== :: SetUserSettings -> SetUserSettings -> Bool
$c== :: SetUserSettings -> SetUserSettings -> Bool
Prelude.Eq, Int -> SetUserSettings -> ShowS
[SetUserSettings] -> ShowS
SetUserSettings -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetUserSettings] -> ShowS
$cshowList :: [SetUserSettings] -> ShowS
show :: SetUserSettings -> String
$cshow :: SetUserSettings -> String
showsPrec :: Int -> SetUserSettings -> ShowS
$cshowsPrec :: Int -> SetUserSettings -> ShowS
Prelude.Show, forall x. Rep SetUserSettings x -> SetUserSettings
forall x. SetUserSettings -> Rep SetUserSettings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetUserSettings x -> SetUserSettings
$cfrom :: forall x. SetUserSettings -> Rep SetUserSettings x
Prelude.Generic)

-- |
-- Create a value of 'SetUserSettings' 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', 'setUserSettings_accessToken' - A valid access token that Amazon Cognito issued to the user whose user
-- settings you want to configure.
--
-- 'mfaOptions', 'setUserSettings_mfaOptions' - You can use this parameter only to set an SMS configuration that uses
-- SMS for delivery.
newSetUserSettings ::
  -- | 'accessToken'
  Prelude.Text ->
  SetUserSettings
newSetUserSettings :: Text -> SetUserSettings
newSetUserSettings Text
pAccessToken_ =
  SetUserSettings'
    { $sel:accessToken:SetUserSettings' :: Sensitive Text
accessToken =
        forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pAccessToken_,
      $sel:mfaOptions:SetUserSettings' :: [MFAOptionType]
mfaOptions = forall a. Monoid a => a
Prelude.mempty
    }

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

-- | You can use this parameter only to set an SMS configuration that uses
-- SMS for delivery.
setUserSettings_mfaOptions :: Lens.Lens' SetUserSettings [MFAOptionType]
setUserSettings_mfaOptions :: Lens' SetUserSettings [MFAOptionType]
setUserSettings_mfaOptions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetUserSettings' {[MFAOptionType]
mfaOptions :: [MFAOptionType]
$sel:mfaOptions:SetUserSettings' :: SetUserSettings -> [MFAOptionType]
mfaOptions} -> [MFAOptionType]
mfaOptions) (\s :: SetUserSettings
s@SetUserSettings' {} [MFAOptionType]
a -> SetUserSettings
s {$sel:mfaOptions:SetUserSettings' :: [MFAOptionType]
mfaOptions = [MFAOptionType]
a} :: SetUserSettings) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest SetUserSettings where
  type
    AWSResponse SetUserSettings =
      SetUserSettingsResponse
  request :: (Service -> Service) -> SetUserSettings -> Request SetUserSettings
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 SetUserSettings
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SetUserSettings)))
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 -> SetUserSettingsResponse
SetUserSettingsResponse'
            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 SetUserSettings where
  hashWithSalt :: Int -> SetUserSettings -> Int
hashWithSalt Int
_salt SetUserSettings' {[MFAOptionType]
Sensitive Text
mfaOptions :: [MFAOptionType]
accessToken :: Sensitive Text
$sel:mfaOptions:SetUserSettings' :: SetUserSettings -> [MFAOptionType]
$sel:accessToken:SetUserSettings' :: SetUserSettings -> Sensitive Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
accessToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [MFAOptionType]
mfaOptions

instance Prelude.NFData SetUserSettings where
  rnf :: SetUserSettings -> ()
rnf SetUserSettings' {[MFAOptionType]
Sensitive Text
mfaOptions :: [MFAOptionType]
accessToken :: Sensitive Text
$sel:mfaOptions:SetUserSettings' :: SetUserSettings -> [MFAOptionType]
$sel:accessToken:SetUserSettings' :: SetUserSettings -> Sensitive Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
accessToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [MFAOptionType]
mfaOptions

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

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

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

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

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

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

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