{-# 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.AddCustomAttributes
-- 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)
--
-- Adds additional user attributes to the user pool schema.
module Amazonka.CognitoIdentityProvider.AddCustomAttributes
  ( -- * Creating a Request
    AddCustomAttributes (..),
    newAddCustomAttributes,

    -- * Request Lenses
    addCustomAttributes_userPoolId,
    addCustomAttributes_customAttributes,

    -- * Destructuring the Response
    AddCustomAttributesResponse (..),
    newAddCustomAttributesResponse,

    -- * Response Lenses
    addCustomAttributesResponse_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 add custom attributes.
--
-- /See:/ 'newAddCustomAttributes' smart constructor.
data AddCustomAttributes = AddCustomAttributes'
  { -- | The user pool ID for the user pool where you want to add custom
    -- attributes.
    AddCustomAttributes -> Text
userPoolId :: Prelude.Text,
    -- | An array of custom attributes, such as Mutable and Name.
    AddCustomAttributes -> NonEmpty SchemaAttributeType
customAttributes :: Prelude.NonEmpty SchemaAttributeType
  }
  deriving (AddCustomAttributes -> AddCustomAttributes -> Bool
(AddCustomAttributes -> AddCustomAttributes -> Bool)
-> (AddCustomAttributes -> AddCustomAttributes -> Bool)
-> Eq AddCustomAttributes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddCustomAttributes -> AddCustomAttributes -> Bool
$c/= :: AddCustomAttributes -> AddCustomAttributes -> Bool
== :: AddCustomAttributes -> AddCustomAttributes -> Bool
$c== :: AddCustomAttributes -> AddCustomAttributes -> Bool
Prelude.Eq, ReadPrec [AddCustomAttributes]
ReadPrec AddCustomAttributes
Int -> ReadS AddCustomAttributes
ReadS [AddCustomAttributes]
(Int -> ReadS AddCustomAttributes)
-> ReadS [AddCustomAttributes]
-> ReadPrec AddCustomAttributes
-> ReadPrec [AddCustomAttributes]
-> Read AddCustomAttributes
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddCustomAttributes]
$creadListPrec :: ReadPrec [AddCustomAttributes]
readPrec :: ReadPrec AddCustomAttributes
$creadPrec :: ReadPrec AddCustomAttributes
readList :: ReadS [AddCustomAttributes]
$creadList :: ReadS [AddCustomAttributes]
readsPrec :: Int -> ReadS AddCustomAttributes
$creadsPrec :: Int -> ReadS AddCustomAttributes
Prelude.Read, Int -> AddCustomAttributes -> ShowS
[AddCustomAttributes] -> ShowS
AddCustomAttributes -> String
(Int -> AddCustomAttributes -> ShowS)
-> (AddCustomAttributes -> String)
-> ([AddCustomAttributes] -> ShowS)
-> Show AddCustomAttributes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddCustomAttributes] -> ShowS
$cshowList :: [AddCustomAttributes] -> ShowS
show :: AddCustomAttributes -> String
$cshow :: AddCustomAttributes -> String
showsPrec :: Int -> AddCustomAttributes -> ShowS
$cshowsPrec :: Int -> AddCustomAttributes -> ShowS
Prelude.Show, (forall x. AddCustomAttributes -> Rep AddCustomAttributes x)
-> (forall x. Rep AddCustomAttributes x -> AddCustomAttributes)
-> Generic AddCustomAttributes
forall x. Rep AddCustomAttributes x -> AddCustomAttributes
forall x. AddCustomAttributes -> Rep AddCustomAttributes x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddCustomAttributes x -> AddCustomAttributes
$cfrom :: forall x. AddCustomAttributes -> Rep AddCustomAttributes x
Prelude.Generic)

-- |
-- Create a value of 'AddCustomAttributes' 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:
--
-- 'userPoolId', 'addCustomAttributes_userPoolId' - The user pool ID for the user pool where you want to add custom
-- attributes.
--
-- 'customAttributes', 'addCustomAttributes_customAttributes' - An array of custom attributes, such as Mutable and Name.
newAddCustomAttributes ::
  -- | 'userPoolId'
  Prelude.Text ->
  -- | 'customAttributes'
  Prelude.NonEmpty SchemaAttributeType ->
  AddCustomAttributes
newAddCustomAttributes :: Text -> NonEmpty SchemaAttributeType -> AddCustomAttributes
newAddCustomAttributes
  Text
pUserPoolId_
  NonEmpty SchemaAttributeType
pCustomAttributes_ =
    AddCustomAttributes' :: Text -> NonEmpty SchemaAttributeType -> AddCustomAttributes
AddCustomAttributes'
      { $sel:userPoolId:AddCustomAttributes' :: Text
userPoolId = Text
pUserPoolId_,
        $sel:customAttributes:AddCustomAttributes' :: NonEmpty SchemaAttributeType
customAttributes =
          Tagged
  (NonEmpty SchemaAttributeType)
  (Identity (NonEmpty SchemaAttributeType))
-> Tagged
     (NonEmpty SchemaAttributeType)
     (Identity (NonEmpty SchemaAttributeType))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty SchemaAttributeType)
   (Identity (NonEmpty SchemaAttributeType))
 -> Tagged
      (NonEmpty SchemaAttributeType)
      (Identity (NonEmpty SchemaAttributeType)))
-> NonEmpty SchemaAttributeType -> NonEmpty SchemaAttributeType
forall t b. AReview t b -> b -> t
Lens.# NonEmpty SchemaAttributeType
pCustomAttributes_
      }

-- | The user pool ID for the user pool where you want to add custom
-- attributes.
addCustomAttributes_userPoolId :: Lens.Lens' AddCustomAttributes Prelude.Text
addCustomAttributes_userPoolId :: (Text -> f Text) -> AddCustomAttributes -> f AddCustomAttributes
addCustomAttributes_userPoolId = (AddCustomAttributes -> Text)
-> (AddCustomAttributes -> Text -> AddCustomAttributes)
-> Lens AddCustomAttributes AddCustomAttributes Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddCustomAttributes' {Text
userPoolId :: Text
$sel:userPoolId:AddCustomAttributes' :: AddCustomAttributes -> Text
userPoolId} -> Text
userPoolId) (\s :: AddCustomAttributes
s@AddCustomAttributes' {} Text
a -> AddCustomAttributes
s {$sel:userPoolId:AddCustomAttributes' :: Text
userPoolId = Text
a} :: AddCustomAttributes)

-- | An array of custom attributes, such as Mutable and Name.
addCustomAttributes_customAttributes :: Lens.Lens' AddCustomAttributes (Prelude.NonEmpty SchemaAttributeType)
addCustomAttributes_customAttributes :: (NonEmpty SchemaAttributeType -> f (NonEmpty SchemaAttributeType))
-> AddCustomAttributes -> f AddCustomAttributes
addCustomAttributes_customAttributes = (AddCustomAttributes -> NonEmpty SchemaAttributeType)
-> (AddCustomAttributes
    -> NonEmpty SchemaAttributeType -> AddCustomAttributes)
-> Lens
     AddCustomAttributes
     AddCustomAttributes
     (NonEmpty SchemaAttributeType)
     (NonEmpty SchemaAttributeType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddCustomAttributes' {NonEmpty SchemaAttributeType
customAttributes :: NonEmpty SchemaAttributeType
$sel:customAttributes:AddCustomAttributes' :: AddCustomAttributes -> NonEmpty SchemaAttributeType
customAttributes} -> NonEmpty SchemaAttributeType
customAttributes) (\s :: AddCustomAttributes
s@AddCustomAttributes' {} NonEmpty SchemaAttributeType
a -> AddCustomAttributes
s {$sel:customAttributes:AddCustomAttributes' :: NonEmpty SchemaAttributeType
customAttributes = NonEmpty SchemaAttributeType
a} :: AddCustomAttributes) ((NonEmpty SchemaAttributeType -> f (NonEmpty SchemaAttributeType))
 -> AddCustomAttributes -> f AddCustomAttributes)
-> ((NonEmpty SchemaAttributeType
     -> f (NonEmpty SchemaAttributeType))
    -> NonEmpty SchemaAttributeType
    -> f (NonEmpty SchemaAttributeType))
-> (NonEmpty SchemaAttributeType
    -> f (NonEmpty SchemaAttributeType))
-> AddCustomAttributes
-> f AddCustomAttributes
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty SchemaAttributeType -> f (NonEmpty SchemaAttributeType))
-> NonEmpty SchemaAttributeType -> f (NonEmpty SchemaAttributeType)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest AddCustomAttributes where
  type
    AWSResponse AddCustomAttributes =
      AddCustomAttributesResponse
  request :: AddCustomAttributes -> Request AddCustomAttributes
request = Service -> AddCustomAttributes -> Request AddCustomAttributes
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AddCustomAttributes
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddCustomAttributes)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse AddCustomAttributes))
-> Logger
-> Service
-> Proxy AddCustomAttributes
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddCustomAttributes)))
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 -> AddCustomAttributesResponse
AddCustomAttributesResponse'
            (Int -> AddCustomAttributesResponse)
-> Either String Int -> Either String AddCustomAttributesResponse
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 AddCustomAttributes

instance Prelude.NFData AddCustomAttributes

instance Core.ToHeaders AddCustomAttributes where
  toHeaders :: AddCustomAttributes -> ResponseHeaders
toHeaders =
    ResponseHeaders -> AddCustomAttributes -> 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.AddCustomAttributes" ::
                          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 AddCustomAttributes where
  toJSON :: AddCustomAttributes -> Value
toJSON AddCustomAttributes' {NonEmpty SchemaAttributeType
Text
customAttributes :: NonEmpty SchemaAttributeType
userPoolId :: Text
$sel:customAttributes:AddCustomAttributes' :: AddCustomAttributes -> NonEmpty SchemaAttributeType
$sel:userPoolId:AddCustomAttributes' :: AddCustomAttributes -> 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
"UserPoolId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
userPoolId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"CustomAttributes" Text -> NonEmpty SchemaAttributeType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty SchemaAttributeType
customAttributes)
          ]
      )

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

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

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

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

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

instance Prelude.NFData AddCustomAttributesResponse