{-# 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-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)
--
-- 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.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 get the device.
--
-- /See:/ 'newGetDevice' smart constructor.
data GetDevice = GetDevice'
  { -- | The access token.
    GetDevice -> Maybe (Sensitive Text)
accessToken :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | The device key.
    GetDevice -> Text
deviceKey :: Prelude.Text
  }
  deriving (GetDevice -> GetDevice -> Bool
(GetDevice -> GetDevice -> Bool)
-> (GetDevice -> GetDevice -> Bool) -> Eq GetDevice
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
(Int -> GetDevice -> ShowS)
-> (GetDevice -> String)
-> ([GetDevice] -> ShowS)
-> Show GetDevice
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. GetDevice -> Rep GetDevice x)
-> (forall x. Rep GetDevice x -> GetDevice) -> Generic GetDevice
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' - The access token.
--
-- 'deviceKey', 'getDevice_deviceKey' - The device key.
newGetDevice ::
  -- | 'deviceKey'
  Prelude.Text ->
  GetDevice
newGetDevice :: Text -> GetDevice
newGetDevice Text
pDeviceKey_ =
  GetDevice' :: Maybe (Sensitive Text) -> Text -> GetDevice
GetDevice'
    { $sel:accessToken:GetDevice' :: Maybe (Sensitive Text)
accessToken = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:deviceKey:GetDevice' :: Text
deviceKey = Text
pDeviceKey_
    }

-- | The access token.
getDevice_accessToken :: Lens.Lens' GetDevice (Prelude.Maybe Prelude.Text)
getDevice_accessToken :: (Maybe Text -> f (Maybe Text)) -> GetDevice -> f GetDevice
getDevice_accessToken = (GetDevice -> Maybe (Sensitive Text))
-> (GetDevice -> Maybe (Sensitive Text) -> GetDevice)
-> Lens
     GetDevice
     GetDevice
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
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) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> GetDevice -> f GetDevice)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> GetDevice
-> f GetDevice
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
     (Maybe Text)
     (Maybe Text)
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 AnIso (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | The device key.
getDevice_deviceKey :: Lens.Lens' GetDevice Prelude.Text
getDevice_deviceKey :: (Text -> f Text) -> GetDevice -> f GetDevice
getDevice_deviceKey = (GetDevice -> Text)
-> (GetDevice -> Text -> GetDevice)
-> Lens GetDevice GetDevice Text Text
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 :: GetDevice -> Request GetDevice
request = Service -> GetDevice -> Request GetDevice
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetDevice
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDevice)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetDevice))
-> Logger
-> Service
-> Proxy GetDevice
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDevice)))
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 ->
          Int -> DeviceType -> GetDeviceResponse
GetDeviceResponse'
            (Int -> DeviceType -> GetDeviceResponse)
-> Either String Int
-> Either String (DeviceType -> GetDeviceResponse)
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))
            Either String (DeviceType -> GetDeviceResponse)
-> Either String DeviceType -> Either String GetDeviceResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String DeviceType
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"Device")
      )

instance Prelude.Hashable GetDevice

instance Prelude.NFData GetDevice

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

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

instance Core.ToQuery GetDevice where
  toQuery :: GetDevice -> QueryString
toQuery = QueryString -> GetDevice -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(GetDeviceResponse -> GetDeviceResponse -> Bool)
-> (GetDeviceResponse -> GetDeviceResponse -> Bool)
-> Eq GetDeviceResponse
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
(Int -> GetDeviceResponse -> ShowS)
-> (GetDeviceResponse -> String)
-> ([GetDeviceResponse] -> ShowS)
-> Show GetDeviceResponse
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. GetDeviceResponse -> Rep GetDeviceResponse x)
-> (forall x. Rep GetDeviceResponse x -> GetDeviceResponse)
-> Generic GetDeviceResponse
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' :: Int -> DeviceType -> GetDeviceResponse
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 :: (Int -> f Int) -> GetDeviceResponse -> f GetDeviceResponse
getDeviceResponse_httpStatus = (GetDeviceResponse -> Int)
-> (GetDeviceResponse -> Int -> GetDeviceResponse)
-> Lens GetDeviceResponse GetDeviceResponse Int Int
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 :: (DeviceType -> f DeviceType)
-> GetDeviceResponse -> f GetDeviceResponse
getDeviceResponse_device = (GetDeviceResponse -> DeviceType)
-> (GetDeviceResponse -> DeviceType -> GetDeviceResponse)
-> Lens GetDeviceResponse GetDeviceResponse DeviceType DeviceType
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