{-# 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.Support.DescribeAttachment
-- 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)
--
-- Returns the attachment that has the specified ID. Attachments can
-- include screenshots, error logs, or other files that describe your
-- issue. Attachment IDs are generated by the case management system when
-- you add an attachment to a case or case communication. Attachment IDs
-- are returned in the AttachmentDetails objects that are returned by the
-- DescribeCommunications operation.
--
-- -   You must have a Business or Enterprise Support plan to use the AWS
--     Support API.
--
-- -   If you call the AWS Support API from an account that does not have a
--     Business or Enterprise Support plan, the
--     @SubscriptionRequiredException@ error message appears. For
--     information about changing your support plan, see
--     <http://aws.amazon.com/premiumsupport/ AWS Support>.
module Amazonka.Support.DescribeAttachment
  ( -- * Creating a Request
    DescribeAttachment (..),
    newDescribeAttachment,

    -- * Request Lenses
    describeAttachment_attachmentId,

    -- * Destructuring the Response
    DescribeAttachmentResponse (..),
    newDescribeAttachmentResponse,

    -- * Response Lenses
    describeAttachmentResponse_attachment,
    describeAttachmentResponse_httpStatus,
  )
where

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
import Amazonka.Support.Types

-- | /See:/ 'newDescribeAttachment' smart constructor.
data DescribeAttachment = DescribeAttachment'
  { -- | The ID of the attachment to return. Attachment IDs are returned by the
    -- DescribeCommunications operation.
    DescribeAttachment -> Text
attachmentId :: Prelude.Text
  }
  deriving (DescribeAttachment -> DescribeAttachment -> Bool
(DescribeAttachment -> DescribeAttachment -> Bool)
-> (DescribeAttachment -> DescribeAttachment -> Bool)
-> Eq DescribeAttachment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeAttachment -> DescribeAttachment -> Bool
$c/= :: DescribeAttachment -> DescribeAttachment -> Bool
== :: DescribeAttachment -> DescribeAttachment -> Bool
$c== :: DescribeAttachment -> DescribeAttachment -> Bool
Prelude.Eq, ReadPrec [DescribeAttachment]
ReadPrec DescribeAttachment
Int -> ReadS DescribeAttachment
ReadS [DescribeAttachment]
(Int -> ReadS DescribeAttachment)
-> ReadS [DescribeAttachment]
-> ReadPrec DescribeAttachment
-> ReadPrec [DescribeAttachment]
-> Read DescribeAttachment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeAttachment]
$creadListPrec :: ReadPrec [DescribeAttachment]
readPrec :: ReadPrec DescribeAttachment
$creadPrec :: ReadPrec DescribeAttachment
readList :: ReadS [DescribeAttachment]
$creadList :: ReadS [DescribeAttachment]
readsPrec :: Int -> ReadS DescribeAttachment
$creadsPrec :: Int -> ReadS DescribeAttachment
Prelude.Read, Int -> DescribeAttachment -> ShowS
[DescribeAttachment] -> ShowS
DescribeAttachment -> String
(Int -> DescribeAttachment -> ShowS)
-> (DescribeAttachment -> String)
-> ([DescribeAttachment] -> ShowS)
-> Show DescribeAttachment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeAttachment] -> ShowS
$cshowList :: [DescribeAttachment] -> ShowS
show :: DescribeAttachment -> String
$cshow :: DescribeAttachment -> String
showsPrec :: Int -> DescribeAttachment -> ShowS
$cshowsPrec :: Int -> DescribeAttachment -> ShowS
Prelude.Show, (forall x. DescribeAttachment -> Rep DescribeAttachment x)
-> (forall x. Rep DescribeAttachment x -> DescribeAttachment)
-> Generic DescribeAttachment
forall x. Rep DescribeAttachment x -> DescribeAttachment
forall x. DescribeAttachment -> Rep DescribeAttachment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeAttachment x -> DescribeAttachment
$cfrom :: forall x. DescribeAttachment -> Rep DescribeAttachment x
Prelude.Generic)

-- |
-- Create a value of 'DescribeAttachment' 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:
--
-- 'attachmentId', 'describeAttachment_attachmentId' - The ID of the attachment to return. Attachment IDs are returned by the
-- DescribeCommunications operation.
newDescribeAttachment ::
  -- | 'attachmentId'
  Prelude.Text ->
  DescribeAttachment
newDescribeAttachment :: Text -> DescribeAttachment
newDescribeAttachment Text
pAttachmentId_ =
  DescribeAttachment' :: Text -> DescribeAttachment
DescribeAttachment' {$sel:attachmentId:DescribeAttachment' :: Text
attachmentId = Text
pAttachmentId_}

-- | The ID of the attachment to return. Attachment IDs are returned by the
-- DescribeCommunications operation.
describeAttachment_attachmentId :: Lens.Lens' DescribeAttachment Prelude.Text
describeAttachment_attachmentId :: (Text -> f Text) -> DescribeAttachment -> f DescribeAttachment
describeAttachment_attachmentId = (DescribeAttachment -> Text)
-> (DescribeAttachment -> Text -> DescribeAttachment)
-> Lens DescribeAttachment DescribeAttachment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeAttachment' {Text
attachmentId :: Text
$sel:attachmentId:DescribeAttachment' :: DescribeAttachment -> Text
attachmentId} -> Text
attachmentId) (\s :: DescribeAttachment
s@DescribeAttachment' {} Text
a -> DescribeAttachment
s {$sel:attachmentId:DescribeAttachment' :: Text
attachmentId = Text
a} :: DescribeAttachment)

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

instance Prelude.NFData DescribeAttachment

instance Core.ToHeaders DescribeAttachment where
  toHeaders :: DescribeAttachment -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeAttachment -> 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
"AWSSupport_20130415.DescribeAttachment" ::
                          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 DescribeAttachment where
  toJSON :: DescribeAttachment -> Value
toJSON DescribeAttachment' {Text
attachmentId :: Text
$sel:attachmentId:DescribeAttachment' :: DescribeAttachment -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"attachmentId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
attachmentId)]
      )

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

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

-- | The content and file name of the attachment returned by the
-- DescribeAttachment operation.
--
-- /See:/ 'newDescribeAttachmentResponse' smart constructor.
data DescribeAttachmentResponse = DescribeAttachmentResponse'
  { -- | This object includes the attachment content and file name.
    --
    -- In the previous response syntax, the value for the @data@ parameter
    -- appears as @blob@, which is represented as a base64-encoded string. The
    -- value for @fileName@ is the name of the attachment, such as
    -- @troubleshoot-screenshot.png@.
    DescribeAttachmentResponse -> Maybe Attachment
attachment :: Prelude.Maybe Attachment,
    -- | The response's http status code.
    DescribeAttachmentResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeAttachmentResponse -> DescribeAttachmentResponse -> Bool
(DescribeAttachmentResponse -> DescribeAttachmentResponse -> Bool)
-> (DescribeAttachmentResponse
    -> DescribeAttachmentResponse -> Bool)
-> Eq DescribeAttachmentResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeAttachmentResponse -> DescribeAttachmentResponse -> Bool
$c/= :: DescribeAttachmentResponse -> DescribeAttachmentResponse -> Bool
== :: DescribeAttachmentResponse -> DescribeAttachmentResponse -> Bool
$c== :: DescribeAttachmentResponse -> DescribeAttachmentResponse -> Bool
Prelude.Eq, ReadPrec [DescribeAttachmentResponse]
ReadPrec DescribeAttachmentResponse
Int -> ReadS DescribeAttachmentResponse
ReadS [DescribeAttachmentResponse]
(Int -> ReadS DescribeAttachmentResponse)
-> ReadS [DescribeAttachmentResponse]
-> ReadPrec DescribeAttachmentResponse
-> ReadPrec [DescribeAttachmentResponse]
-> Read DescribeAttachmentResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeAttachmentResponse]
$creadListPrec :: ReadPrec [DescribeAttachmentResponse]
readPrec :: ReadPrec DescribeAttachmentResponse
$creadPrec :: ReadPrec DescribeAttachmentResponse
readList :: ReadS [DescribeAttachmentResponse]
$creadList :: ReadS [DescribeAttachmentResponse]
readsPrec :: Int -> ReadS DescribeAttachmentResponse
$creadsPrec :: Int -> ReadS DescribeAttachmentResponse
Prelude.Read, Int -> DescribeAttachmentResponse -> ShowS
[DescribeAttachmentResponse] -> ShowS
DescribeAttachmentResponse -> String
(Int -> DescribeAttachmentResponse -> ShowS)
-> (DescribeAttachmentResponse -> String)
-> ([DescribeAttachmentResponse] -> ShowS)
-> Show DescribeAttachmentResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeAttachmentResponse] -> ShowS
$cshowList :: [DescribeAttachmentResponse] -> ShowS
show :: DescribeAttachmentResponse -> String
$cshow :: DescribeAttachmentResponse -> String
showsPrec :: Int -> DescribeAttachmentResponse -> ShowS
$cshowsPrec :: Int -> DescribeAttachmentResponse -> ShowS
Prelude.Show, (forall x.
 DescribeAttachmentResponse -> Rep DescribeAttachmentResponse x)
-> (forall x.
    Rep DescribeAttachmentResponse x -> DescribeAttachmentResponse)
-> Generic DescribeAttachmentResponse
forall x.
Rep DescribeAttachmentResponse x -> DescribeAttachmentResponse
forall x.
DescribeAttachmentResponse -> Rep DescribeAttachmentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeAttachmentResponse x -> DescribeAttachmentResponse
$cfrom :: forall x.
DescribeAttachmentResponse -> Rep DescribeAttachmentResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeAttachmentResponse' 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:
--
-- 'attachment', 'describeAttachmentResponse_attachment' - This object includes the attachment content and file name.
--
-- In the previous response syntax, the value for the @data@ parameter
-- appears as @blob@, which is represented as a base64-encoded string. The
-- value for @fileName@ is the name of the attachment, such as
-- @troubleshoot-screenshot.png@.
--
-- 'httpStatus', 'describeAttachmentResponse_httpStatus' - The response's http status code.
newDescribeAttachmentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeAttachmentResponse
newDescribeAttachmentResponse :: Int -> DescribeAttachmentResponse
newDescribeAttachmentResponse Int
pHttpStatus_ =
  DescribeAttachmentResponse' :: Maybe Attachment -> Int -> DescribeAttachmentResponse
DescribeAttachmentResponse'
    { $sel:attachment:DescribeAttachmentResponse' :: Maybe Attachment
attachment =
        Maybe Attachment
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeAttachmentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | This object includes the attachment content and file name.
--
-- In the previous response syntax, the value for the @data@ parameter
-- appears as @blob@, which is represented as a base64-encoded string. The
-- value for @fileName@ is the name of the attachment, such as
-- @troubleshoot-screenshot.png@.
describeAttachmentResponse_attachment :: Lens.Lens' DescribeAttachmentResponse (Prelude.Maybe Attachment)
describeAttachmentResponse_attachment :: (Maybe Attachment -> f (Maybe Attachment))
-> DescribeAttachmentResponse -> f DescribeAttachmentResponse
describeAttachmentResponse_attachment = (DescribeAttachmentResponse -> Maybe Attachment)
-> (DescribeAttachmentResponse
    -> Maybe Attachment -> DescribeAttachmentResponse)
-> Lens
     DescribeAttachmentResponse
     DescribeAttachmentResponse
     (Maybe Attachment)
     (Maybe Attachment)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeAttachmentResponse' {Maybe Attachment
attachment :: Maybe Attachment
$sel:attachment:DescribeAttachmentResponse' :: DescribeAttachmentResponse -> Maybe Attachment
attachment} -> Maybe Attachment
attachment) (\s :: DescribeAttachmentResponse
s@DescribeAttachmentResponse' {} Maybe Attachment
a -> DescribeAttachmentResponse
s {$sel:attachment:DescribeAttachmentResponse' :: Maybe Attachment
attachment = Maybe Attachment
a} :: DescribeAttachmentResponse)

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

instance Prelude.NFData DescribeAttachmentResponse