{-# 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.WorkDocs.GetCurrentUser
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves details of the current user for whom the authentication token
-- was generated. This is not a valid action for SigV4 (administrative API)
-- clients.
--
-- This action requires an authentication token. To get an authentication
-- token, register an application with Amazon WorkDocs. For more
-- information, see
-- <https://docs.aws.amazon.com/workdocs/latest/developerguide/wd-auth-user.html Authentication and Access Control for User Applications>
-- in the /Amazon WorkDocs Developer Guide/.
module Amazonka.WorkDocs.GetCurrentUser
  ( -- * Creating a Request
    GetCurrentUser (..),
    newGetCurrentUser,

    -- * Request Lenses
    getCurrentUser_authenticationToken,

    -- * Destructuring the Response
    GetCurrentUserResponse (..),
    newGetCurrentUserResponse,

    -- * Response Lenses
    getCurrentUserResponse_user,
    getCurrentUserResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetCurrentUser' smart constructor.
data GetCurrentUser = GetCurrentUser'
  { -- | Amazon WorkDocs authentication token.
    GetCurrentUser -> Sensitive Text
authenticationToken :: Data.Sensitive Prelude.Text
  }
  deriving (GetCurrentUser -> GetCurrentUser -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCurrentUser -> GetCurrentUser -> Bool
$c/= :: GetCurrentUser -> GetCurrentUser -> Bool
== :: GetCurrentUser -> GetCurrentUser -> Bool
$c== :: GetCurrentUser -> GetCurrentUser -> Bool
Prelude.Eq, Int -> GetCurrentUser -> ShowS
[GetCurrentUser] -> ShowS
GetCurrentUser -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCurrentUser] -> ShowS
$cshowList :: [GetCurrentUser] -> ShowS
show :: GetCurrentUser -> String
$cshow :: GetCurrentUser -> String
showsPrec :: Int -> GetCurrentUser -> ShowS
$cshowsPrec :: Int -> GetCurrentUser -> ShowS
Prelude.Show, forall x. Rep GetCurrentUser x -> GetCurrentUser
forall x. GetCurrentUser -> Rep GetCurrentUser x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCurrentUser x -> GetCurrentUser
$cfrom :: forall x. GetCurrentUser -> Rep GetCurrentUser x
Prelude.Generic)

-- |
-- Create a value of 'GetCurrentUser' 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:
--
-- 'authenticationToken', 'getCurrentUser_authenticationToken' - Amazon WorkDocs authentication token.
newGetCurrentUser ::
  -- | 'authenticationToken'
  Prelude.Text ->
  GetCurrentUser
newGetCurrentUser :: Text -> GetCurrentUser
newGetCurrentUser Text
pAuthenticationToken_ =
  GetCurrentUser'
    { $sel:authenticationToken:GetCurrentUser' :: Sensitive Text
authenticationToken =
        forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pAuthenticationToken_
    }

-- | Amazon WorkDocs authentication token.
getCurrentUser_authenticationToken :: Lens.Lens' GetCurrentUser Prelude.Text
getCurrentUser_authenticationToken :: Lens' GetCurrentUser Text
getCurrentUser_authenticationToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCurrentUser' {Sensitive Text
authenticationToken :: Sensitive Text
$sel:authenticationToken:GetCurrentUser' :: GetCurrentUser -> Sensitive Text
authenticationToken} -> Sensitive Text
authenticationToken) (\s :: GetCurrentUser
s@GetCurrentUser' {} Sensitive Text
a -> GetCurrentUser
s {$sel:authenticationToken:GetCurrentUser' :: Sensitive Text
authenticationToken = Sensitive Text
a} :: GetCurrentUser) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Core.AWSRequest GetCurrentUser where
  type
    AWSResponse GetCurrentUser =
      GetCurrentUserResponse
  request :: (Service -> Service) -> GetCurrentUser -> Request GetCurrentUser
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetCurrentUser
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCurrentUser)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe User -> Int -> GetCurrentUserResponse
GetCurrentUserResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"User")
            forall (f :: * -> *) a b. Applicative f => 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 GetCurrentUser where
  hashWithSalt :: Int -> GetCurrentUser -> Int
hashWithSalt Int
_salt GetCurrentUser' {Sensitive Text
authenticationToken :: Sensitive Text
$sel:authenticationToken:GetCurrentUser' :: GetCurrentUser -> Sensitive Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
authenticationToken

instance Prelude.NFData GetCurrentUser where
  rnf :: GetCurrentUser -> ()
rnf GetCurrentUser' {Sensitive Text
authenticationToken :: Sensitive Text
$sel:authenticationToken:GetCurrentUser' :: GetCurrentUser -> Sensitive Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
authenticationToken

instance Data.ToHeaders GetCurrentUser where
  toHeaders :: GetCurrentUser -> ResponseHeaders
toHeaders GetCurrentUser' {Sensitive Text
authenticationToken :: Sensitive Text
$sel:authenticationToken:GetCurrentUser' :: GetCurrentUser -> Sensitive Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"Authentication" forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# Sensitive Text
authenticationToken,
        HeaderName
"Content-Type"
          forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# (ByteString
"application/x-amz-json-1.1" :: Prelude.ByteString)
      ]

instance Data.ToPath GetCurrentUser where
  toPath :: GetCurrentUser -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/api/v1/me"

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

-- | /See:/ 'newGetCurrentUserResponse' smart constructor.
data GetCurrentUserResponse = GetCurrentUserResponse'
  { -- | Metadata of the user.
    GetCurrentUserResponse -> Maybe User
user :: Prelude.Maybe User,
    -- | The response's http status code.
    GetCurrentUserResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetCurrentUserResponse -> GetCurrentUserResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCurrentUserResponse -> GetCurrentUserResponse -> Bool
$c/= :: GetCurrentUserResponse -> GetCurrentUserResponse -> Bool
== :: GetCurrentUserResponse -> GetCurrentUserResponse -> Bool
$c== :: GetCurrentUserResponse -> GetCurrentUserResponse -> Bool
Prelude.Eq, Int -> GetCurrentUserResponse -> ShowS
[GetCurrentUserResponse] -> ShowS
GetCurrentUserResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCurrentUserResponse] -> ShowS
$cshowList :: [GetCurrentUserResponse] -> ShowS
show :: GetCurrentUserResponse -> String
$cshow :: GetCurrentUserResponse -> String
showsPrec :: Int -> GetCurrentUserResponse -> ShowS
$cshowsPrec :: Int -> GetCurrentUserResponse -> ShowS
Prelude.Show, forall x. Rep GetCurrentUserResponse x -> GetCurrentUserResponse
forall x. GetCurrentUserResponse -> Rep GetCurrentUserResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCurrentUserResponse x -> GetCurrentUserResponse
$cfrom :: forall x. GetCurrentUserResponse -> Rep GetCurrentUserResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetCurrentUserResponse' 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:
--
-- 'user', 'getCurrentUserResponse_user' - Metadata of the user.
--
-- 'httpStatus', 'getCurrentUserResponse_httpStatus' - The response's http status code.
newGetCurrentUserResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCurrentUserResponse
newGetCurrentUserResponse :: Int -> GetCurrentUserResponse
newGetCurrentUserResponse Int
pHttpStatus_ =
  GetCurrentUserResponse'
    { $sel:user:GetCurrentUserResponse' :: Maybe User
user = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCurrentUserResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Metadata of the user.
getCurrentUserResponse_user :: Lens.Lens' GetCurrentUserResponse (Prelude.Maybe User)
getCurrentUserResponse_user :: Lens' GetCurrentUserResponse (Maybe User)
getCurrentUserResponse_user = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCurrentUserResponse' {Maybe User
user :: Maybe User
$sel:user:GetCurrentUserResponse' :: GetCurrentUserResponse -> Maybe User
user} -> Maybe User
user) (\s :: GetCurrentUserResponse
s@GetCurrentUserResponse' {} Maybe User
a -> GetCurrentUserResponse
s {$sel:user:GetCurrentUserResponse' :: Maybe User
user = Maybe User
a} :: GetCurrentUserResponse)

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

instance Prelude.NFData GetCurrentUserResponse where
  rnf :: GetCurrentUserResponse -> ()
rnf GetCurrentUserResponse' {Int
Maybe User
httpStatus :: Int
user :: Maybe User
$sel:httpStatus:GetCurrentUserResponse' :: GetCurrentUserResponse -> Int
$sel:user:GetCurrentUserResponse' :: GetCurrentUserResponse -> Maybe User
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe User
user
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus