{-# 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.DescribeIdentity
-- 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)
--
-- Returns metadata related to the given identity, including when the
-- identity was created and any associated linked logins.
--
-- You must use AWS Developer credentials to call this API.
module Amazonka.CognitoIdentity.DescribeIdentity
  ( -- * Creating a Request
    DescribeIdentity (..),
    newDescribeIdentity,

    -- * Request Lenses
    describeIdentity_identityId,

    -- * Destructuring the Response
    IdentityDescription (..),
    newIdentityDescription,

    -- * Response Lenses
    identityDescription_lastModifiedDate,
    identityDescription_creationDate,
    identityDescription_logins,
    identityDescription_identityId,
  )
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 @DescribeIdentity@ action.
--
-- /See:/ 'newDescribeIdentity' smart constructor.
data DescribeIdentity = DescribeIdentity'
  { -- | A unique identifier in the format REGION:GUID.
    DescribeIdentity -> Text
identityId :: Prelude.Text
  }
  deriving (DescribeIdentity -> DescribeIdentity -> Bool
(DescribeIdentity -> DescribeIdentity -> Bool)
-> (DescribeIdentity -> DescribeIdentity -> Bool)
-> Eq DescribeIdentity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeIdentity -> DescribeIdentity -> Bool
$c/= :: DescribeIdentity -> DescribeIdentity -> Bool
== :: DescribeIdentity -> DescribeIdentity -> Bool
$c== :: DescribeIdentity -> DescribeIdentity -> Bool
Prelude.Eq, ReadPrec [DescribeIdentity]
ReadPrec DescribeIdentity
Int -> ReadS DescribeIdentity
ReadS [DescribeIdentity]
(Int -> ReadS DescribeIdentity)
-> ReadS [DescribeIdentity]
-> ReadPrec DescribeIdentity
-> ReadPrec [DescribeIdentity]
-> Read DescribeIdentity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeIdentity]
$creadListPrec :: ReadPrec [DescribeIdentity]
readPrec :: ReadPrec DescribeIdentity
$creadPrec :: ReadPrec DescribeIdentity
readList :: ReadS [DescribeIdentity]
$creadList :: ReadS [DescribeIdentity]
readsPrec :: Int -> ReadS DescribeIdentity
$creadsPrec :: Int -> ReadS DescribeIdentity
Prelude.Read, Int -> DescribeIdentity -> ShowS
[DescribeIdentity] -> ShowS
DescribeIdentity -> String
(Int -> DescribeIdentity -> ShowS)
-> (DescribeIdentity -> String)
-> ([DescribeIdentity] -> ShowS)
-> Show DescribeIdentity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeIdentity] -> ShowS
$cshowList :: [DescribeIdentity] -> ShowS
show :: DescribeIdentity -> String
$cshow :: DescribeIdentity -> String
showsPrec :: Int -> DescribeIdentity -> ShowS
$cshowsPrec :: Int -> DescribeIdentity -> ShowS
Prelude.Show, (forall x. DescribeIdentity -> Rep DescribeIdentity x)
-> (forall x. Rep DescribeIdentity x -> DescribeIdentity)
-> Generic DescribeIdentity
forall x. Rep DescribeIdentity x -> DescribeIdentity
forall x. DescribeIdentity -> Rep DescribeIdentity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeIdentity x -> DescribeIdentity
$cfrom :: forall x. DescribeIdentity -> Rep DescribeIdentity x
Prelude.Generic)

-- |
-- Create a value of 'DescribeIdentity' 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', 'describeIdentity_identityId' - A unique identifier in the format REGION:GUID.
newDescribeIdentity ::
  -- | 'identityId'
  Prelude.Text ->
  DescribeIdentity
newDescribeIdentity :: Text -> DescribeIdentity
newDescribeIdentity Text
pIdentityId_ =
  DescribeIdentity' :: Text -> DescribeIdentity
DescribeIdentity' {$sel:identityId:DescribeIdentity' :: Text
identityId = Text
pIdentityId_}

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

instance Core.AWSRequest DescribeIdentity where
  type
    AWSResponse DescribeIdentity =
      IdentityDescription
  request :: DescribeIdentity -> Request DescribeIdentity
request = Service -> DescribeIdentity -> Request DescribeIdentity
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeIdentity
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeIdentity)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeIdentity))
-> Logger
-> Service
-> Proxy DescribeIdentity
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeIdentity)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> Object -> Either String IdentityDescription
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable DescribeIdentity

instance Prelude.NFData DescribeIdentity

instance Core.ToHeaders DescribeIdentity where
  toHeaders :: DescribeIdentity -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeIdentity -> 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
"AWSCognitoIdentityService.DescribeIdentity" ::
                          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 DescribeIdentity where
  toJSON :: DescribeIdentity -> Value
toJSON DescribeIdentity' {Text
identityId :: Text
$sel:identityId:DescribeIdentity' :: DescribeIdentity -> 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)]
      )

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

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