{-# 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.IoT.GetOTAUpdate
-- 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 an OTA update.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions GetOTAUpdate>
-- action.
module Amazonka.IoT.GetOTAUpdate
  ( -- * Creating a Request
    GetOTAUpdate (..),
    newGetOTAUpdate,

    -- * Request Lenses
    getOTAUpdate_otaUpdateId,

    -- * Destructuring the Response
    GetOTAUpdateResponse (..),
    newGetOTAUpdateResponse,

    -- * Response Lenses
    getOTAUpdateResponse_otaUpdateInfo,
    getOTAUpdateResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types
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:/ 'newGetOTAUpdate' smart constructor.
data GetOTAUpdate = GetOTAUpdate'
  { -- | The OTA update ID.
    GetOTAUpdate -> Text
otaUpdateId :: Prelude.Text
  }
  deriving (GetOTAUpdate -> GetOTAUpdate -> Bool
(GetOTAUpdate -> GetOTAUpdate -> Bool)
-> (GetOTAUpdate -> GetOTAUpdate -> Bool) -> Eq GetOTAUpdate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetOTAUpdate -> GetOTAUpdate -> Bool
$c/= :: GetOTAUpdate -> GetOTAUpdate -> Bool
== :: GetOTAUpdate -> GetOTAUpdate -> Bool
$c== :: GetOTAUpdate -> GetOTAUpdate -> Bool
Prelude.Eq, ReadPrec [GetOTAUpdate]
ReadPrec GetOTAUpdate
Int -> ReadS GetOTAUpdate
ReadS [GetOTAUpdate]
(Int -> ReadS GetOTAUpdate)
-> ReadS [GetOTAUpdate]
-> ReadPrec GetOTAUpdate
-> ReadPrec [GetOTAUpdate]
-> Read GetOTAUpdate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetOTAUpdate]
$creadListPrec :: ReadPrec [GetOTAUpdate]
readPrec :: ReadPrec GetOTAUpdate
$creadPrec :: ReadPrec GetOTAUpdate
readList :: ReadS [GetOTAUpdate]
$creadList :: ReadS [GetOTAUpdate]
readsPrec :: Int -> ReadS GetOTAUpdate
$creadsPrec :: Int -> ReadS GetOTAUpdate
Prelude.Read, Int -> GetOTAUpdate -> ShowS
[GetOTAUpdate] -> ShowS
GetOTAUpdate -> String
(Int -> GetOTAUpdate -> ShowS)
-> (GetOTAUpdate -> String)
-> ([GetOTAUpdate] -> ShowS)
-> Show GetOTAUpdate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetOTAUpdate] -> ShowS
$cshowList :: [GetOTAUpdate] -> ShowS
show :: GetOTAUpdate -> String
$cshow :: GetOTAUpdate -> String
showsPrec :: Int -> GetOTAUpdate -> ShowS
$cshowsPrec :: Int -> GetOTAUpdate -> ShowS
Prelude.Show, (forall x. GetOTAUpdate -> Rep GetOTAUpdate x)
-> (forall x. Rep GetOTAUpdate x -> GetOTAUpdate)
-> Generic GetOTAUpdate
forall x. Rep GetOTAUpdate x -> GetOTAUpdate
forall x. GetOTAUpdate -> Rep GetOTAUpdate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetOTAUpdate x -> GetOTAUpdate
$cfrom :: forall x. GetOTAUpdate -> Rep GetOTAUpdate x
Prelude.Generic)

-- |
-- Create a value of 'GetOTAUpdate' 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:
--
-- 'otaUpdateId', 'getOTAUpdate_otaUpdateId' - The OTA update ID.
newGetOTAUpdate ::
  -- | 'otaUpdateId'
  Prelude.Text ->
  GetOTAUpdate
newGetOTAUpdate :: Text -> GetOTAUpdate
newGetOTAUpdate Text
pOtaUpdateId_ =
  GetOTAUpdate' :: Text -> GetOTAUpdate
GetOTAUpdate' {$sel:otaUpdateId:GetOTAUpdate' :: Text
otaUpdateId = Text
pOtaUpdateId_}

-- | The OTA update ID.
getOTAUpdate_otaUpdateId :: Lens.Lens' GetOTAUpdate Prelude.Text
getOTAUpdate_otaUpdateId :: (Text -> f Text) -> GetOTAUpdate -> f GetOTAUpdate
getOTAUpdate_otaUpdateId = (GetOTAUpdate -> Text)
-> (GetOTAUpdate -> Text -> GetOTAUpdate)
-> Lens GetOTAUpdate GetOTAUpdate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetOTAUpdate' {Text
otaUpdateId :: Text
$sel:otaUpdateId:GetOTAUpdate' :: GetOTAUpdate -> Text
otaUpdateId} -> Text
otaUpdateId) (\s :: GetOTAUpdate
s@GetOTAUpdate' {} Text
a -> GetOTAUpdate
s {$sel:otaUpdateId:GetOTAUpdate' :: Text
otaUpdateId = Text
a} :: GetOTAUpdate)

instance Core.AWSRequest GetOTAUpdate where
  type AWSResponse GetOTAUpdate = GetOTAUpdateResponse
  request :: GetOTAUpdate -> Request GetOTAUpdate
request = Service -> GetOTAUpdate -> Request GetOTAUpdate
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetOTAUpdate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetOTAUpdate)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetOTAUpdate))
-> Logger
-> Service
-> Proxy GetOTAUpdate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetOTAUpdate)))
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 OTAUpdateInfo -> Int -> GetOTAUpdateResponse
GetOTAUpdateResponse'
            (Maybe OTAUpdateInfo -> Int -> GetOTAUpdateResponse)
-> Either String (Maybe OTAUpdateInfo)
-> Either String (Int -> GetOTAUpdateResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe OTAUpdateInfo)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"otaUpdateInfo")
            Either String (Int -> GetOTAUpdateResponse)
-> Either String Int -> Either String GetOTAUpdateResponse
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 GetOTAUpdate

instance Prelude.NFData GetOTAUpdate

instance Core.ToHeaders GetOTAUpdate where
  toHeaders :: GetOTAUpdate -> ResponseHeaders
toHeaders = ResponseHeaders -> GetOTAUpdate -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath GetOTAUpdate where
  toPath :: GetOTAUpdate -> ByteString
toPath GetOTAUpdate' {Text
otaUpdateId :: Text
$sel:otaUpdateId:GetOTAUpdate' :: GetOTAUpdate -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/otaUpdates/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
otaUpdateId]

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

-- | /See:/ 'newGetOTAUpdateResponse' smart constructor.
data GetOTAUpdateResponse = GetOTAUpdateResponse'
  { -- | The OTA update info.
    GetOTAUpdateResponse -> Maybe OTAUpdateInfo
otaUpdateInfo :: Prelude.Maybe OTAUpdateInfo,
    -- | The response's http status code.
    GetOTAUpdateResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetOTAUpdateResponse -> GetOTAUpdateResponse -> Bool
(GetOTAUpdateResponse -> GetOTAUpdateResponse -> Bool)
-> (GetOTAUpdateResponse -> GetOTAUpdateResponse -> Bool)
-> Eq GetOTAUpdateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetOTAUpdateResponse -> GetOTAUpdateResponse -> Bool
$c/= :: GetOTAUpdateResponse -> GetOTAUpdateResponse -> Bool
== :: GetOTAUpdateResponse -> GetOTAUpdateResponse -> Bool
$c== :: GetOTAUpdateResponse -> GetOTAUpdateResponse -> Bool
Prelude.Eq, ReadPrec [GetOTAUpdateResponse]
ReadPrec GetOTAUpdateResponse
Int -> ReadS GetOTAUpdateResponse
ReadS [GetOTAUpdateResponse]
(Int -> ReadS GetOTAUpdateResponse)
-> ReadS [GetOTAUpdateResponse]
-> ReadPrec GetOTAUpdateResponse
-> ReadPrec [GetOTAUpdateResponse]
-> Read GetOTAUpdateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetOTAUpdateResponse]
$creadListPrec :: ReadPrec [GetOTAUpdateResponse]
readPrec :: ReadPrec GetOTAUpdateResponse
$creadPrec :: ReadPrec GetOTAUpdateResponse
readList :: ReadS [GetOTAUpdateResponse]
$creadList :: ReadS [GetOTAUpdateResponse]
readsPrec :: Int -> ReadS GetOTAUpdateResponse
$creadsPrec :: Int -> ReadS GetOTAUpdateResponse
Prelude.Read, Int -> GetOTAUpdateResponse -> ShowS
[GetOTAUpdateResponse] -> ShowS
GetOTAUpdateResponse -> String
(Int -> GetOTAUpdateResponse -> ShowS)
-> (GetOTAUpdateResponse -> String)
-> ([GetOTAUpdateResponse] -> ShowS)
-> Show GetOTAUpdateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetOTAUpdateResponse] -> ShowS
$cshowList :: [GetOTAUpdateResponse] -> ShowS
show :: GetOTAUpdateResponse -> String
$cshow :: GetOTAUpdateResponse -> String
showsPrec :: Int -> GetOTAUpdateResponse -> ShowS
$cshowsPrec :: Int -> GetOTAUpdateResponse -> ShowS
Prelude.Show, (forall x. GetOTAUpdateResponse -> Rep GetOTAUpdateResponse x)
-> (forall x. Rep GetOTAUpdateResponse x -> GetOTAUpdateResponse)
-> Generic GetOTAUpdateResponse
forall x. Rep GetOTAUpdateResponse x -> GetOTAUpdateResponse
forall x. GetOTAUpdateResponse -> Rep GetOTAUpdateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetOTAUpdateResponse x -> GetOTAUpdateResponse
$cfrom :: forall x. GetOTAUpdateResponse -> Rep GetOTAUpdateResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetOTAUpdateResponse' 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:
--
-- 'otaUpdateInfo', 'getOTAUpdateResponse_otaUpdateInfo' - The OTA update info.
--
-- 'httpStatus', 'getOTAUpdateResponse_httpStatus' - The response's http status code.
newGetOTAUpdateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetOTAUpdateResponse
newGetOTAUpdateResponse :: Int -> GetOTAUpdateResponse
newGetOTAUpdateResponse Int
pHttpStatus_ =
  GetOTAUpdateResponse' :: Maybe OTAUpdateInfo -> Int -> GetOTAUpdateResponse
GetOTAUpdateResponse'
    { $sel:otaUpdateInfo:GetOTAUpdateResponse' :: Maybe OTAUpdateInfo
otaUpdateInfo =
        Maybe OTAUpdateInfo
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetOTAUpdateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The OTA update info.
getOTAUpdateResponse_otaUpdateInfo :: Lens.Lens' GetOTAUpdateResponse (Prelude.Maybe OTAUpdateInfo)
getOTAUpdateResponse_otaUpdateInfo :: (Maybe OTAUpdateInfo -> f (Maybe OTAUpdateInfo))
-> GetOTAUpdateResponse -> f GetOTAUpdateResponse
getOTAUpdateResponse_otaUpdateInfo = (GetOTAUpdateResponse -> Maybe OTAUpdateInfo)
-> (GetOTAUpdateResponse
    -> Maybe OTAUpdateInfo -> GetOTAUpdateResponse)
-> Lens
     GetOTAUpdateResponse
     GetOTAUpdateResponse
     (Maybe OTAUpdateInfo)
     (Maybe OTAUpdateInfo)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetOTAUpdateResponse' {Maybe OTAUpdateInfo
otaUpdateInfo :: Maybe OTAUpdateInfo
$sel:otaUpdateInfo:GetOTAUpdateResponse' :: GetOTAUpdateResponse -> Maybe OTAUpdateInfo
otaUpdateInfo} -> Maybe OTAUpdateInfo
otaUpdateInfo) (\s :: GetOTAUpdateResponse
s@GetOTAUpdateResponse' {} Maybe OTAUpdateInfo
a -> GetOTAUpdateResponse
s {$sel:otaUpdateInfo:GetOTAUpdateResponse' :: Maybe OTAUpdateInfo
otaUpdateInfo = Maybe OTAUpdateInfo
a} :: GetOTAUpdateResponse)

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

instance Prelude.NFData GetOTAUpdateResponse