{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types
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
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]
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
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. 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' {$sel:otaUpdateId:GetOTAUpdate' :: Text
otaUpdateId = Text
pOtaUpdateId_}

-- | The OTA update ID.
getOTAUpdate_otaUpdateId :: Lens.Lens' GetOTAUpdate Prelude.Text
getOTAUpdate_otaUpdateId :: Lens' GetOTAUpdate Text
getOTAUpdate_otaUpdateId = 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 :: (Service -> Service) -> GetOTAUpdate -> Request GetOTAUpdate
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 GetOTAUpdate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetOTAUpdate)))
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 OTAUpdateInfo -> Int -> GetOTAUpdateResponse
GetOTAUpdateResponse'
            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
"otaUpdateInfo")
            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 GetOTAUpdate where
  hashWithSalt :: Int -> GetOTAUpdate -> Int
hashWithSalt Int
_salt GetOTAUpdate' {Text
otaUpdateId :: Text
$sel:otaUpdateId:GetOTAUpdate' :: GetOTAUpdate -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
otaUpdateId

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

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

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

instance Data.ToQuery GetOTAUpdate where
  toQuery :: GetOTAUpdate -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:otaUpdateInfo:GetOTAUpdateResponse' :: Maybe OTAUpdateInfo
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 :: Lens' GetOTAUpdateResponse (Maybe OTAUpdateInfo)
getOTAUpdateResponse_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 :: Lens' GetOTAUpdateResponse Int
getOTAUpdateResponse_httpStatus = 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 where
  rnf :: GetOTAUpdateResponse -> ()
rnf GetOTAUpdateResponse' {Int
Maybe OTAUpdateInfo
httpStatus :: Int
otaUpdateInfo :: Maybe OTAUpdateInfo
$sel:httpStatus:GetOTAUpdateResponse' :: GetOTAUpdateResponse -> Int
$sel:otaUpdateInfo:GetOTAUpdateResponse' :: GetOTAUpdateResponse -> Maybe OTAUpdateInfo
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe OTAUpdateInfo
otaUpdateInfo
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus