{-# 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.CognitoIdentity.UnlinkIdentity
-- 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)
--
-- Unlinks a federated identity from an existing account. Unlinked logins
-- will be considered new identities next time they are seen. Removing the
-- last linked login will make this identity inaccessible.
--
-- This is a public API. You do not need any credentials to call this API.
module Amazonka.CognitoIdentity.UnlinkIdentity
  ( -- * Creating a Request
    UnlinkIdentity (..),
    newUnlinkIdentity,

    -- * Request Lenses
    unlinkIdentity_identityId,
    unlinkIdentity_logins,
    unlinkIdentity_loginsToRemove,

    -- * Destructuring the Response
    UnlinkIdentityResponse (..),
    newUnlinkIdentityResponse,
  )
where

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

-- | Input to the UnlinkIdentity action.
--
-- /See:/ 'newUnlinkIdentity' smart constructor.
data UnlinkIdentity = UnlinkIdentity'
  { -- | A unique identifier in the format REGION:GUID.
    UnlinkIdentity -> Text
identityId :: Prelude.Text,
    -- | A set of optional name-value pairs that map provider names to provider
    -- tokens.
    UnlinkIdentity -> HashMap Text Text
logins :: Prelude.HashMap Prelude.Text Prelude.Text,
    -- | Provider names to unlink from this identity.
    UnlinkIdentity -> [Text]
loginsToRemove :: [Prelude.Text]
  }
  deriving (UnlinkIdentity -> UnlinkIdentity -> Bool
(UnlinkIdentity -> UnlinkIdentity -> Bool)
-> (UnlinkIdentity -> UnlinkIdentity -> Bool) -> Eq UnlinkIdentity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnlinkIdentity -> UnlinkIdentity -> Bool
$c/= :: UnlinkIdentity -> UnlinkIdentity -> Bool
== :: UnlinkIdentity -> UnlinkIdentity -> Bool
$c== :: UnlinkIdentity -> UnlinkIdentity -> Bool
Prelude.Eq, ReadPrec [UnlinkIdentity]
ReadPrec UnlinkIdentity
Int -> ReadS UnlinkIdentity
ReadS [UnlinkIdentity]
(Int -> ReadS UnlinkIdentity)
-> ReadS [UnlinkIdentity]
-> ReadPrec UnlinkIdentity
-> ReadPrec [UnlinkIdentity]
-> Read UnlinkIdentity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UnlinkIdentity]
$creadListPrec :: ReadPrec [UnlinkIdentity]
readPrec :: ReadPrec UnlinkIdentity
$creadPrec :: ReadPrec UnlinkIdentity
readList :: ReadS [UnlinkIdentity]
$creadList :: ReadS [UnlinkIdentity]
readsPrec :: Int -> ReadS UnlinkIdentity
$creadsPrec :: Int -> ReadS UnlinkIdentity
Prelude.Read, Int -> UnlinkIdentity -> ShowS
[UnlinkIdentity] -> ShowS
UnlinkIdentity -> String
(Int -> UnlinkIdentity -> ShowS)
-> (UnlinkIdentity -> String)
-> ([UnlinkIdentity] -> ShowS)
-> Show UnlinkIdentity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnlinkIdentity] -> ShowS
$cshowList :: [UnlinkIdentity] -> ShowS
show :: UnlinkIdentity -> String
$cshow :: UnlinkIdentity -> String
showsPrec :: Int -> UnlinkIdentity -> ShowS
$cshowsPrec :: Int -> UnlinkIdentity -> ShowS
Prelude.Show, (forall x. UnlinkIdentity -> Rep UnlinkIdentity x)
-> (forall x. Rep UnlinkIdentity x -> UnlinkIdentity)
-> Generic UnlinkIdentity
forall x. Rep UnlinkIdentity x -> UnlinkIdentity
forall x. UnlinkIdentity -> Rep UnlinkIdentity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UnlinkIdentity x -> UnlinkIdentity
$cfrom :: forall x. UnlinkIdentity -> Rep UnlinkIdentity x
Prelude.Generic)

-- |
-- Create a value of 'UnlinkIdentity' 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:
--
-- 'identityId', 'unlinkIdentity_identityId' - A unique identifier in the format REGION:GUID.
--
-- 'logins', 'unlinkIdentity_logins' - A set of optional name-value pairs that map provider names to provider
-- tokens.
--
-- 'loginsToRemove', 'unlinkIdentity_loginsToRemove' - Provider names to unlink from this identity.
newUnlinkIdentity ::
  -- | 'identityId'
  Prelude.Text ->
  UnlinkIdentity
newUnlinkIdentity :: Text -> UnlinkIdentity
newUnlinkIdentity Text
pIdentityId_ =
  UnlinkIdentity' :: Text -> HashMap Text Text -> [Text] -> UnlinkIdentity
UnlinkIdentity'
    { $sel:identityId:UnlinkIdentity' :: Text
identityId = Text
pIdentityId_,
      $sel:logins:UnlinkIdentity' :: HashMap Text Text
logins = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty,
      $sel:loginsToRemove:UnlinkIdentity' :: [Text]
loginsToRemove = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | A unique identifier in the format REGION:GUID.
unlinkIdentity_identityId :: Lens.Lens' UnlinkIdentity Prelude.Text
unlinkIdentity_identityId :: (Text -> f Text) -> UnlinkIdentity -> f UnlinkIdentity
unlinkIdentity_identityId = (UnlinkIdentity -> Text)
-> (UnlinkIdentity -> Text -> UnlinkIdentity)
-> Lens UnlinkIdentity UnlinkIdentity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UnlinkIdentity' {Text
identityId :: Text
$sel:identityId:UnlinkIdentity' :: UnlinkIdentity -> Text
identityId} -> Text
identityId) (\s :: UnlinkIdentity
s@UnlinkIdentity' {} Text
a -> UnlinkIdentity
s {$sel:identityId:UnlinkIdentity' :: Text
identityId = Text
a} :: UnlinkIdentity)

-- | A set of optional name-value pairs that map provider names to provider
-- tokens.
unlinkIdentity_logins :: Lens.Lens' UnlinkIdentity (Prelude.HashMap Prelude.Text Prelude.Text)
unlinkIdentity_logins :: (HashMap Text Text -> f (HashMap Text Text))
-> UnlinkIdentity -> f UnlinkIdentity
unlinkIdentity_logins = (UnlinkIdentity -> HashMap Text Text)
-> (UnlinkIdentity -> HashMap Text Text -> UnlinkIdentity)
-> Lens
     UnlinkIdentity
     UnlinkIdentity
     (HashMap Text Text)
     (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UnlinkIdentity' {HashMap Text Text
logins :: HashMap Text Text
$sel:logins:UnlinkIdentity' :: UnlinkIdentity -> HashMap Text Text
logins} -> HashMap Text Text
logins) (\s :: UnlinkIdentity
s@UnlinkIdentity' {} HashMap Text Text
a -> UnlinkIdentity
s {$sel:logins:UnlinkIdentity' :: HashMap Text Text
logins = HashMap Text Text
a} :: UnlinkIdentity) ((HashMap Text Text -> f (HashMap Text Text))
 -> UnlinkIdentity -> f UnlinkIdentity)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> UnlinkIdentity
-> f UnlinkIdentity
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Provider names to unlink from this identity.
unlinkIdentity_loginsToRemove :: Lens.Lens' UnlinkIdentity [Prelude.Text]
unlinkIdentity_loginsToRemove :: ([Text] -> f [Text]) -> UnlinkIdentity -> f UnlinkIdentity
unlinkIdentity_loginsToRemove = (UnlinkIdentity -> [Text])
-> (UnlinkIdentity -> [Text] -> UnlinkIdentity)
-> Lens UnlinkIdentity UnlinkIdentity [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UnlinkIdentity' {[Text]
loginsToRemove :: [Text]
$sel:loginsToRemove:UnlinkIdentity' :: UnlinkIdentity -> [Text]
loginsToRemove} -> [Text]
loginsToRemove) (\s :: UnlinkIdentity
s@UnlinkIdentity' {} [Text]
a -> UnlinkIdentity
s {$sel:loginsToRemove:UnlinkIdentity' :: [Text]
loginsToRemove = [Text]
a} :: UnlinkIdentity) (([Text] -> f [Text]) -> UnlinkIdentity -> f UnlinkIdentity)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> UnlinkIdentity
-> f UnlinkIdentity
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest UnlinkIdentity where
  type
    AWSResponse UnlinkIdentity =
      UnlinkIdentityResponse
  request :: UnlinkIdentity -> Request UnlinkIdentity
request = Service -> UnlinkIdentity -> Request UnlinkIdentity
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UnlinkIdentity
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UnlinkIdentity)))
response =
    AWSResponse UnlinkIdentity
-> Logger
-> Service
-> Proxy UnlinkIdentity
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UnlinkIdentity)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse UnlinkIdentity
UnlinkIdentityResponse
UnlinkIdentityResponse'

instance Prelude.Hashable UnlinkIdentity

instance Prelude.NFData UnlinkIdentity

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

instance Core.ToJSON UnlinkIdentity where
  toJSON :: UnlinkIdentity -> Value
toJSON UnlinkIdentity' {[Text]
Text
HashMap Text Text
loginsToRemove :: [Text]
logins :: HashMap Text Text
identityId :: Text
$sel:loginsToRemove:UnlinkIdentity' :: UnlinkIdentity -> [Text]
$sel:logins:UnlinkIdentity' :: UnlinkIdentity -> HashMap Text Text
$sel:identityId:UnlinkIdentity' :: UnlinkIdentity -> 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
"IdentityId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
identityId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Logins" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
logins),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"LoginsToRemove" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
loginsToRemove)
          ]
      )

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

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

-- | /See:/ 'newUnlinkIdentityResponse' smart constructor.
data UnlinkIdentityResponse = UnlinkIdentityResponse'
  {
  }
  deriving (UnlinkIdentityResponse -> UnlinkIdentityResponse -> Bool
(UnlinkIdentityResponse -> UnlinkIdentityResponse -> Bool)
-> (UnlinkIdentityResponse -> UnlinkIdentityResponse -> Bool)
-> Eq UnlinkIdentityResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnlinkIdentityResponse -> UnlinkIdentityResponse -> Bool
$c/= :: UnlinkIdentityResponse -> UnlinkIdentityResponse -> Bool
== :: UnlinkIdentityResponse -> UnlinkIdentityResponse -> Bool
$c== :: UnlinkIdentityResponse -> UnlinkIdentityResponse -> Bool
Prelude.Eq, ReadPrec [UnlinkIdentityResponse]
ReadPrec UnlinkIdentityResponse
Int -> ReadS UnlinkIdentityResponse
ReadS [UnlinkIdentityResponse]
(Int -> ReadS UnlinkIdentityResponse)
-> ReadS [UnlinkIdentityResponse]
-> ReadPrec UnlinkIdentityResponse
-> ReadPrec [UnlinkIdentityResponse]
-> Read UnlinkIdentityResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UnlinkIdentityResponse]
$creadListPrec :: ReadPrec [UnlinkIdentityResponse]
readPrec :: ReadPrec UnlinkIdentityResponse
$creadPrec :: ReadPrec UnlinkIdentityResponse
readList :: ReadS [UnlinkIdentityResponse]
$creadList :: ReadS [UnlinkIdentityResponse]
readsPrec :: Int -> ReadS UnlinkIdentityResponse
$creadsPrec :: Int -> ReadS UnlinkIdentityResponse
Prelude.Read, Int -> UnlinkIdentityResponse -> ShowS
[UnlinkIdentityResponse] -> ShowS
UnlinkIdentityResponse -> String
(Int -> UnlinkIdentityResponse -> ShowS)
-> (UnlinkIdentityResponse -> String)
-> ([UnlinkIdentityResponse] -> ShowS)
-> Show UnlinkIdentityResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnlinkIdentityResponse] -> ShowS
$cshowList :: [UnlinkIdentityResponse] -> ShowS
show :: UnlinkIdentityResponse -> String
$cshow :: UnlinkIdentityResponse -> String
showsPrec :: Int -> UnlinkIdentityResponse -> ShowS
$cshowsPrec :: Int -> UnlinkIdentityResponse -> ShowS
Prelude.Show, (forall x. UnlinkIdentityResponse -> Rep UnlinkIdentityResponse x)
-> (forall x.
    Rep UnlinkIdentityResponse x -> UnlinkIdentityResponse)
-> Generic UnlinkIdentityResponse
forall x. Rep UnlinkIdentityResponse x -> UnlinkIdentityResponse
forall x. UnlinkIdentityResponse -> Rep UnlinkIdentityResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UnlinkIdentityResponse x -> UnlinkIdentityResponse
$cfrom :: forall x. UnlinkIdentityResponse -> Rep UnlinkIdentityResponse x
Prelude.Generic)

-- |
-- Create a value of 'UnlinkIdentityResponse' 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.
newUnlinkIdentityResponse ::
  UnlinkIdentityResponse
newUnlinkIdentityResponse :: UnlinkIdentityResponse
newUnlinkIdentityResponse = UnlinkIdentityResponse
UnlinkIdentityResponse'

instance Prelude.NFData UnlinkIdentityResponse