{-# 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.GetDevice
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets the device.
module Amazonka.CognitoIdentityProvider.GetDevice
  ( -- * Creating a Request
    GetDevice (..),
    newGetDevice,

    -- * Request Lenses
    getDevice_accessToken,
    getDevice_deviceKey,

    -- * Destructuring the Response
    GetDeviceResponse (..),
    newGetDeviceResponse,

    -- * Response Lenses
    getDeviceResponse_httpStatus,
    getDeviceResponse_device,
  )
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 get the device.
--
-- /See:/ 'newGetDevice' smart constructor.
data GetDevice = GetDevice'
  { -- | A valid access token that Amazon Cognito issued to the user whose device
    -- information you want to request.
    GetDevice -> Maybe (Sensitive Text)
accessToken :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The device key.
    GetDevice -> Text
deviceKey :: Prelude.Text
  }
  deriving (GetDevice -> GetDevice -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDevice -> GetDevice -> Bool
$c/= :: GetDevice -> GetDevice -> Bool
== :: GetDevice -> GetDevice -> Bool
$c== :: GetDevice -> GetDevice -> Bool
Prelude.Eq, Int -> GetDevice -> ShowS
[GetDevice] -> ShowS
GetDevice -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDevice] -> ShowS
$cshowList :: [GetDevice] -> ShowS
show :: GetDevice -> String
$cshow :: GetDevice -> String
showsPrec :: Int -> GetDevice -> ShowS
$cshowsPrec :: Int -> GetDevice -> ShowS
Prelude.Show, forall x. Rep GetDevice x -> GetDevice
forall x. GetDevice -> Rep GetDevice x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDevice x -> GetDevice
$cfrom :: forall x. GetDevice -> Rep GetDevice x
Prelude.Generic)

-- |
-- Create a value of 'GetDevice' 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', 'getDevice_accessToken' - A valid access token that Amazon Cognito issued to the user whose device
-- information you want to request.
--
-- 'deviceKey', 'getDevice_deviceKey' - The device key.
newGetDevice ::
  -- | 'deviceKey'
  Prelude.Text ->
  GetDevice
newGetDevice :: Text -> GetDevice
newGetDevice Text
pDeviceKey_ =
  GetDevice'
    { $sel:accessToken:GetDevice' :: Maybe (Sensitive Text)
accessToken = forall a. Maybe a
Prelude.Nothing,
      $sel:deviceKey:GetDevice' :: Text
deviceKey = Text
pDeviceKey_
    }

-- | A valid access token that Amazon Cognito issued to the user whose device
-- information you want to request.
getDevice_accessToken :: Lens.Lens' GetDevice (Prelude.Maybe Prelude.Text)
getDevice_accessToken :: Lens' GetDevice (Maybe Text)
getDevice_accessToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDevice' {Maybe (Sensitive Text)
accessToken :: Maybe (Sensitive Text)
$sel:accessToken:GetDevice' :: GetDevice -> Maybe (Sensitive Text)
accessToken} -> Maybe (Sensitive Text)
accessToken) (\s :: GetDevice
s@GetDevice' {} Maybe (Sensitive Text)
a -> GetDevice
s {$sel:accessToken:GetDevice' :: Maybe (Sensitive Text)
accessToken = Maybe (Sensitive Text)
a} :: GetDevice) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The device key.
getDevice_deviceKey :: Lens.Lens' GetDevice Prelude.Text
getDevice_deviceKey :: Lens' GetDevice Text
getDevice_deviceKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDevice' {Text
deviceKey :: Text
$sel:deviceKey:GetDevice' :: GetDevice -> Text
deviceKey} -> Text
deviceKey) (\s :: GetDevice
s@GetDevice' {} Text
a -> GetDevice
s {$sel:deviceKey:GetDevice' :: Text
deviceKey = Text
a} :: GetDevice)

instance Core.AWSRequest GetDevice where
  type AWSResponse GetDevice = GetDeviceResponse
  request :: (Service -> Service) -> GetDevice -> Request GetDevice
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 GetDevice
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDevice)))
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 ->
          Int -> DeviceType -> GetDeviceResponse
GetDeviceResponse'
            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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"Device")
      )

instance Prelude.Hashable GetDevice where
  hashWithSalt :: Int -> GetDevice -> Int
hashWithSalt Int
_salt GetDevice' {Maybe (Sensitive Text)
Text
deviceKey :: Text
accessToken :: Maybe (Sensitive Text)
$sel:deviceKey:GetDevice' :: GetDevice -> Text
$sel:accessToken:GetDevice' :: GetDevice -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
accessToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
deviceKey

instance Prelude.NFData GetDevice where
  rnf :: GetDevice -> ()
rnf GetDevice' {Maybe (Sensitive Text)
Text
deviceKey :: Text
accessToken :: Maybe (Sensitive Text)
$sel:deviceKey:GetDevice' :: GetDevice -> Text
$sel:accessToken:GetDevice' :: GetDevice -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
accessToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
deviceKey

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

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

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

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

-- |
-- Create a value of 'GetDeviceResponse' 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', 'getDeviceResponse_httpStatus' - The response's http status code.
--
-- 'device', 'getDeviceResponse_device' - The device.
newGetDeviceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'device'
  DeviceType ->
  GetDeviceResponse
newGetDeviceResponse :: Int -> DeviceType -> GetDeviceResponse
newGetDeviceResponse Int
pHttpStatus_ DeviceType
pDevice_ =
  GetDeviceResponse'
    { $sel:httpStatus:GetDeviceResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:device:GetDeviceResponse' :: DeviceType
device = DeviceType
pDevice_
    }

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

-- | The device.
getDeviceResponse_device :: Lens.Lens' GetDeviceResponse DeviceType
getDeviceResponse_device :: Lens' GetDeviceResponse DeviceType
getDeviceResponse_device = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDeviceResponse' {DeviceType
device :: DeviceType
$sel:device:GetDeviceResponse' :: GetDeviceResponse -> DeviceType
device} -> DeviceType
device) (\s :: GetDeviceResponse
s@GetDeviceResponse' {} DeviceType
a -> GetDeviceResponse
s {$sel:device:GetDeviceResponse' :: DeviceType
device = DeviceType
a} :: GetDeviceResponse)

instance Prelude.NFData GetDeviceResponse where
  rnf :: GetDeviceResponse -> ()
rnf GetDeviceResponse' {Int
DeviceType
device :: DeviceType
httpStatus :: Int
$sel:device:GetDeviceResponse' :: GetDeviceResponse -> DeviceType
$sel:httpStatus:GetDeviceResponse' :: GetDeviceResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DeviceType
device