{-# 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.ImageBuilder.GetImage
-- 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 image.
module Amazonka.ImageBuilder.GetImage
  ( -- * Creating a Request
    GetImage (..),
    newGetImage,

    -- * Request Lenses
    getImage_imageBuildVersionArn,

    -- * Destructuring the Response
    GetImageResponse (..),
    newGetImageResponse,

    -- * Response Lenses
    getImageResponse_requestId,
    getImageResponse_image,
    getImageResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ImageBuilder.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:/ 'newGetImage' smart constructor.
data GetImage = GetImage'
  { -- | The Amazon Resource Name (ARN) of the image that you want to retrieve.
    GetImage -> Text
imageBuildVersionArn :: Prelude.Text
  }
  deriving (GetImage -> GetImage -> Bool
(GetImage -> GetImage -> Bool)
-> (GetImage -> GetImage -> Bool) -> Eq GetImage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetImage -> GetImage -> Bool
$c/= :: GetImage -> GetImage -> Bool
== :: GetImage -> GetImage -> Bool
$c== :: GetImage -> GetImage -> Bool
Prelude.Eq, ReadPrec [GetImage]
ReadPrec GetImage
Int -> ReadS GetImage
ReadS [GetImage]
(Int -> ReadS GetImage)
-> ReadS [GetImage]
-> ReadPrec GetImage
-> ReadPrec [GetImage]
-> Read GetImage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetImage]
$creadListPrec :: ReadPrec [GetImage]
readPrec :: ReadPrec GetImage
$creadPrec :: ReadPrec GetImage
readList :: ReadS [GetImage]
$creadList :: ReadS [GetImage]
readsPrec :: Int -> ReadS GetImage
$creadsPrec :: Int -> ReadS GetImage
Prelude.Read, Int -> GetImage -> ShowS
[GetImage] -> ShowS
GetImage -> String
(Int -> GetImage -> ShowS)
-> (GetImage -> String) -> ([GetImage] -> ShowS) -> Show GetImage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetImage] -> ShowS
$cshowList :: [GetImage] -> ShowS
show :: GetImage -> String
$cshow :: GetImage -> String
showsPrec :: Int -> GetImage -> ShowS
$cshowsPrec :: Int -> GetImage -> ShowS
Prelude.Show, (forall x. GetImage -> Rep GetImage x)
-> (forall x. Rep GetImage x -> GetImage) -> Generic GetImage
forall x. Rep GetImage x -> GetImage
forall x. GetImage -> Rep GetImage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetImage x -> GetImage
$cfrom :: forall x. GetImage -> Rep GetImage x
Prelude.Generic)

-- |
-- Create a value of 'GetImage' 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:
--
-- 'imageBuildVersionArn', 'getImage_imageBuildVersionArn' - The Amazon Resource Name (ARN) of the image that you want to retrieve.
newGetImage ::
  -- | 'imageBuildVersionArn'
  Prelude.Text ->
  GetImage
newGetImage :: Text -> GetImage
newGetImage Text
pImageBuildVersionArn_ =
  GetImage' :: Text -> GetImage
GetImage'
    { $sel:imageBuildVersionArn:GetImage' :: Text
imageBuildVersionArn =
        Text
pImageBuildVersionArn_
    }

-- | The Amazon Resource Name (ARN) of the image that you want to retrieve.
getImage_imageBuildVersionArn :: Lens.Lens' GetImage Prelude.Text
getImage_imageBuildVersionArn :: (Text -> f Text) -> GetImage -> f GetImage
getImage_imageBuildVersionArn = (GetImage -> Text)
-> (GetImage -> Text -> GetImage)
-> Lens GetImage GetImage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetImage' {Text
imageBuildVersionArn :: Text
$sel:imageBuildVersionArn:GetImage' :: GetImage -> Text
imageBuildVersionArn} -> Text
imageBuildVersionArn) (\s :: GetImage
s@GetImage' {} Text
a -> GetImage
s {$sel:imageBuildVersionArn:GetImage' :: Text
imageBuildVersionArn = Text
a} :: GetImage)

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

instance Prelude.NFData GetImage

instance Core.ToHeaders GetImage where
  toHeaders :: GetImage -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetImage -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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.ToPath GetImage where
  toPath :: GetImage -> ByteString
toPath = ByteString -> GetImage -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/GetImage"

instance Core.ToQuery GetImage where
  toQuery :: GetImage -> QueryString
toQuery GetImage' {Text
imageBuildVersionArn :: Text
$sel:imageBuildVersionArn:GetImage' :: GetImage -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"imageBuildVersionArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
imageBuildVersionArn]

-- | /See:/ 'newGetImageResponse' smart constructor.
data GetImageResponse = GetImageResponse'
  { -- | The request ID that uniquely identifies this request.
    GetImageResponse -> Maybe Text
requestId :: Prelude.Maybe Prelude.Text,
    -- | The image object.
    GetImageResponse -> Maybe Image
image :: Prelude.Maybe Image,
    -- | The response's http status code.
    GetImageResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetImageResponse -> GetImageResponse -> Bool
(GetImageResponse -> GetImageResponse -> Bool)
-> (GetImageResponse -> GetImageResponse -> Bool)
-> Eq GetImageResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetImageResponse -> GetImageResponse -> Bool
$c/= :: GetImageResponse -> GetImageResponse -> Bool
== :: GetImageResponse -> GetImageResponse -> Bool
$c== :: GetImageResponse -> GetImageResponse -> Bool
Prelude.Eq, ReadPrec [GetImageResponse]
ReadPrec GetImageResponse
Int -> ReadS GetImageResponse
ReadS [GetImageResponse]
(Int -> ReadS GetImageResponse)
-> ReadS [GetImageResponse]
-> ReadPrec GetImageResponse
-> ReadPrec [GetImageResponse]
-> Read GetImageResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetImageResponse]
$creadListPrec :: ReadPrec [GetImageResponse]
readPrec :: ReadPrec GetImageResponse
$creadPrec :: ReadPrec GetImageResponse
readList :: ReadS [GetImageResponse]
$creadList :: ReadS [GetImageResponse]
readsPrec :: Int -> ReadS GetImageResponse
$creadsPrec :: Int -> ReadS GetImageResponse
Prelude.Read, Int -> GetImageResponse -> ShowS
[GetImageResponse] -> ShowS
GetImageResponse -> String
(Int -> GetImageResponse -> ShowS)
-> (GetImageResponse -> String)
-> ([GetImageResponse] -> ShowS)
-> Show GetImageResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetImageResponse] -> ShowS
$cshowList :: [GetImageResponse] -> ShowS
show :: GetImageResponse -> String
$cshow :: GetImageResponse -> String
showsPrec :: Int -> GetImageResponse -> ShowS
$cshowsPrec :: Int -> GetImageResponse -> ShowS
Prelude.Show, (forall x. GetImageResponse -> Rep GetImageResponse x)
-> (forall x. Rep GetImageResponse x -> GetImageResponse)
-> Generic GetImageResponse
forall x. Rep GetImageResponse x -> GetImageResponse
forall x. GetImageResponse -> Rep GetImageResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetImageResponse x -> GetImageResponse
$cfrom :: forall x. GetImageResponse -> Rep GetImageResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetImageResponse' 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:
--
-- 'requestId', 'getImageResponse_requestId' - The request ID that uniquely identifies this request.
--
-- 'image', 'getImageResponse_image' - The image object.
--
-- 'httpStatus', 'getImageResponse_httpStatus' - The response's http status code.
newGetImageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetImageResponse
newGetImageResponse :: Int -> GetImageResponse
newGetImageResponse Int
pHttpStatus_ =
  GetImageResponse' :: Maybe Text -> Maybe Image -> Int -> GetImageResponse
GetImageResponse'
    { $sel:requestId:GetImageResponse' :: Maybe Text
requestId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:image:GetImageResponse' :: Maybe Image
image = Maybe Image
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetImageResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The request ID that uniquely identifies this request.
getImageResponse_requestId :: Lens.Lens' GetImageResponse (Prelude.Maybe Prelude.Text)
getImageResponse_requestId :: (Maybe Text -> f (Maybe Text))
-> GetImageResponse -> f GetImageResponse
getImageResponse_requestId = (GetImageResponse -> Maybe Text)
-> (GetImageResponse -> Maybe Text -> GetImageResponse)
-> Lens GetImageResponse GetImageResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetImageResponse' {Maybe Text
requestId :: Maybe Text
$sel:requestId:GetImageResponse' :: GetImageResponse -> Maybe Text
requestId} -> Maybe Text
requestId) (\s :: GetImageResponse
s@GetImageResponse' {} Maybe Text
a -> GetImageResponse
s {$sel:requestId:GetImageResponse' :: Maybe Text
requestId = Maybe Text
a} :: GetImageResponse)

-- | The image object.
getImageResponse_image :: Lens.Lens' GetImageResponse (Prelude.Maybe Image)
getImageResponse_image :: (Maybe Image -> f (Maybe Image))
-> GetImageResponse -> f GetImageResponse
getImageResponse_image = (GetImageResponse -> Maybe Image)
-> (GetImageResponse -> Maybe Image -> GetImageResponse)
-> Lens
     GetImageResponse GetImageResponse (Maybe Image) (Maybe Image)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetImageResponse' {Maybe Image
image :: Maybe Image
$sel:image:GetImageResponse' :: GetImageResponse -> Maybe Image
image} -> Maybe Image
image) (\s :: GetImageResponse
s@GetImageResponse' {} Maybe Image
a -> GetImageResponse
s {$sel:image:GetImageResponse' :: Maybe Image
image = Maybe Image
a} :: GetImageResponse)

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

instance Prelude.NFData GetImageResponse