{-# 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.AlexaBusiness.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 details of a device by device ARN.
module Amazonka.AlexaBusiness.GetDevice
  ( -- * Creating a Request
    GetDevice (..),
    newGetDevice,

    -- * Request Lenses
    getDevice_deviceArn,

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

    -- * Response Lenses
    getDeviceResponse_device,
    getDeviceResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetDevice' smart constructor.
data GetDevice = GetDevice'
  { -- | The ARN of the device for which to request details. Required.
    GetDevice -> Maybe Text
deviceArn :: Prelude.Maybe 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, ReadPrec [GetDevice]
ReadPrec GetDevice
Int -> ReadS GetDevice
ReadS [GetDevice]
(Int -> ReadS GetDevice)
-> ReadS [GetDevice]
-> ReadPrec GetDevice
-> ReadPrec [GetDevice]
-> Read GetDevice
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDevice]
$creadListPrec :: ReadPrec [GetDevice]
readPrec :: ReadPrec GetDevice
$creadPrec :: ReadPrec GetDevice
readList :: ReadS [GetDevice]
$creadList :: ReadS [GetDevice]
readsPrec :: Int -> ReadS GetDevice
$creadsPrec :: Int -> ReadS GetDevice
Prelude.Read, 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:
--
-- 'deviceArn', 'getDevice_deviceArn' - The ARN of the device for which to request details. Required.
newGetDevice ::
  GetDevice
newGetDevice :: GetDevice
newGetDevice =
  GetDevice' :: Maybe Text -> GetDevice
GetDevice' {$sel:deviceArn:GetDevice' :: Maybe Text
deviceArn = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | The ARN of the device for which to request details. Required.
getDevice_deviceArn :: Lens.Lens' GetDevice (Prelude.Maybe Prelude.Text)
getDevice_deviceArn :: (Maybe Text -> f (Maybe Text)) -> GetDevice -> f GetDevice
getDevice_deviceArn = (GetDevice -> Maybe Text)
-> (GetDevice -> Maybe Text -> GetDevice)
-> Lens GetDevice GetDevice (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDevice' {Maybe Text
deviceArn :: Maybe Text
$sel:deviceArn:GetDevice' :: GetDevice -> Maybe Text
deviceArn} -> Maybe Text
deviceArn) (\s :: GetDevice
s@GetDevice' {} Maybe Text
a -> GetDevice
s {$sel:deviceArn:GetDevice' :: Maybe Text
deviceArn = Maybe 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 ->
          Maybe Device -> Int -> GetDeviceResponse
GetDeviceResponse'
            (Maybe Device -> Int -> GetDeviceResponse)
-> Either String (Maybe Device)
-> Either String (Int -> GetDeviceResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Device)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Device")
            Either String (Int -> GetDeviceResponse)
-> Either String Int -> Either String GetDeviceResponse
forall (f :: * -> *) a b. Applicative f => 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))
      )

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
"AlexaForBusiness.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 Text
deviceArn :: Maybe Text
$sel:deviceArn:GetDevice' :: GetDevice -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"DeviceArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
deviceArn]
      )

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

-- | /See:/ 'newGetDeviceResponse' smart constructor.
data GetDeviceResponse = GetDeviceResponse'
  { -- | The details of the device requested. Required.
    GetDeviceResponse -> Maybe Device
device :: Prelude.Maybe Device,
    -- | The response's http status code.
    GetDeviceResponse -> Int
httpStatus :: Prelude.Int
  }
  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, ReadPrec [GetDeviceResponse]
ReadPrec GetDeviceResponse
Int -> ReadS GetDeviceResponse
ReadS [GetDeviceResponse]
(Int -> ReadS GetDeviceResponse)
-> ReadS [GetDeviceResponse]
-> ReadPrec GetDeviceResponse
-> ReadPrec [GetDeviceResponse]
-> Read GetDeviceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDeviceResponse]
$creadListPrec :: ReadPrec [GetDeviceResponse]
readPrec :: ReadPrec GetDeviceResponse
$creadPrec :: ReadPrec GetDeviceResponse
readList :: ReadS [GetDeviceResponse]
$creadList :: ReadS [GetDeviceResponse]
readsPrec :: Int -> ReadS GetDeviceResponse
$creadsPrec :: Int -> ReadS GetDeviceResponse
Prelude.Read, 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:
--
-- 'device', 'getDeviceResponse_device' - The details of the device requested. Required.
--
-- 'httpStatus', 'getDeviceResponse_httpStatus' - The response's http status code.
newGetDeviceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetDeviceResponse
newGetDeviceResponse :: Int -> GetDeviceResponse
newGetDeviceResponse Int
pHttpStatus_ =
  GetDeviceResponse' :: Maybe Device -> Int -> GetDeviceResponse
GetDeviceResponse'
    { $sel:device:GetDeviceResponse' :: Maybe Device
device = Maybe Device
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetDeviceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The details of the device requested. Required.
getDeviceResponse_device :: Lens.Lens' GetDeviceResponse (Prelude.Maybe Device)
getDeviceResponse_device :: (Maybe Device -> f (Maybe Device))
-> GetDeviceResponse -> f GetDeviceResponse
getDeviceResponse_device = (GetDeviceResponse -> Maybe Device)
-> (GetDeviceResponse -> Maybe Device -> GetDeviceResponse)
-> Lens
     GetDeviceResponse GetDeviceResponse (Maybe Device) (Maybe Device)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDeviceResponse' {Maybe Device
device :: Maybe Device
$sel:device:GetDeviceResponse' :: GetDeviceResponse -> Maybe Device
device} -> Maybe Device
device) (\s :: GetDeviceResponse
s@GetDeviceResponse' {} Maybe Device
a -> GetDeviceResponse
s {$sel:device:GetDeviceResponse' :: Maybe Device
device = Maybe Device
a} :: GetDeviceResponse)

-- | 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)

instance Prelude.NFData GetDeviceResponse