{-# 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.WorkMailMessageFlow.GetRawMessageContent
-- 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)
--
-- Retrieves the raw content of an in-transit email message, in MIME
-- format.
module Amazonka.WorkMailMessageFlow.GetRawMessageContent
  ( -- * Creating a Request
    GetRawMessageContent (..),
    newGetRawMessageContent,

    -- * Request Lenses
    getRawMessageContent_messageId,

    -- * Destructuring the Response
    GetRawMessageContentResponse (..),
    newGetRawMessageContentResponse,

    -- * Response Lenses
    getRawMessageContentResponse_httpStatus,
    getRawMessageContentResponse_messageContent,
  )
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.WorkMailMessageFlow.Types

-- | /See:/ 'newGetRawMessageContent' smart constructor.
data GetRawMessageContent = GetRawMessageContent'
  { -- | The identifier of the email message to retrieve.
    GetRawMessageContent -> Text
messageId :: Prelude.Text
  }
  deriving (GetRawMessageContent -> GetRawMessageContent -> Bool
(GetRawMessageContent -> GetRawMessageContent -> Bool)
-> (GetRawMessageContent -> GetRawMessageContent -> Bool)
-> Eq GetRawMessageContent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRawMessageContent -> GetRawMessageContent -> Bool
$c/= :: GetRawMessageContent -> GetRawMessageContent -> Bool
== :: GetRawMessageContent -> GetRawMessageContent -> Bool
$c== :: GetRawMessageContent -> GetRawMessageContent -> Bool
Prelude.Eq, ReadPrec [GetRawMessageContent]
ReadPrec GetRawMessageContent
Int -> ReadS GetRawMessageContent
ReadS [GetRawMessageContent]
(Int -> ReadS GetRawMessageContent)
-> ReadS [GetRawMessageContent]
-> ReadPrec GetRawMessageContent
-> ReadPrec [GetRawMessageContent]
-> Read GetRawMessageContent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRawMessageContent]
$creadListPrec :: ReadPrec [GetRawMessageContent]
readPrec :: ReadPrec GetRawMessageContent
$creadPrec :: ReadPrec GetRawMessageContent
readList :: ReadS [GetRawMessageContent]
$creadList :: ReadS [GetRawMessageContent]
readsPrec :: Int -> ReadS GetRawMessageContent
$creadsPrec :: Int -> ReadS GetRawMessageContent
Prelude.Read, Int -> GetRawMessageContent -> ShowS
[GetRawMessageContent] -> ShowS
GetRawMessageContent -> String
(Int -> GetRawMessageContent -> ShowS)
-> (GetRawMessageContent -> String)
-> ([GetRawMessageContent] -> ShowS)
-> Show GetRawMessageContent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRawMessageContent] -> ShowS
$cshowList :: [GetRawMessageContent] -> ShowS
show :: GetRawMessageContent -> String
$cshow :: GetRawMessageContent -> String
showsPrec :: Int -> GetRawMessageContent -> ShowS
$cshowsPrec :: Int -> GetRawMessageContent -> ShowS
Prelude.Show, (forall x. GetRawMessageContent -> Rep GetRawMessageContent x)
-> (forall x. Rep GetRawMessageContent x -> GetRawMessageContent)
-> Generic GetRawMessageContent
forall x. Rep GetRawMessageContent x -> GetRawMessageContent
forall x. GetRawMessageContent -> Rep GetRawMessageContent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRawMessageContent x -> GetRawMessageContent
$cfrom :: forall x. GetRawMessageContent -> Rep GetRawMessageContent x
Prelude.Generic)

-- |
-- Create a value of 'GetRawMessageContent' 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:
--
-- 'messageId', 'getRawMessageContent_messageId' - The identifier of the email message to retrieve.
newGetRawMessageContent ::
  -- | 'messageId'
  Prelude.Text ->
  GetRawMessageContent
newGetRawMessageContent :: Text -> GetRawMessageContent
newGetRawMessageContent Text
pMessageId_ =
  GetRawMessageContent' :: Text -> GetRawMessageContent
GetRawMessageContent' {$sel:messageId:GetRawMessageContent' :: Text
messageId = Text
pMessageId_}

-- | The identifier of the email message to retrieve.
getRawMessageContent_messageId :: Lens.Lens' GetRawMessageContent Prelude.Text
getRawMessageContent_messageId :: (Text -> f Text) -> GetRawMessageContent -> f GetRawMessageContent
getRawMessageContent_messageId = (GetRawMessageContent -> Text)
-> (GetRawMessageContent -> Text -> GetRawMessageContent)
-> Lens GetRawMessageContent GetRawMessageContent Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRawMessageContent' {Text
messageId :: Text
$sel:messageId:GetRawMessageContent' :: GetRawMessageContent -> Text
messageId} -> Text
messageId) (\s :: GetRawMessageContent
s@GetRawMessageContent' {} Text
a -> GetRawMessageContent
s {$sel:messageId:GetRawMessageContent' :: Text
messageId = Text
a} :: GetRawMessageContent)

instance Core.AWSRequest GetRawMessageContent where
  type
    AWSResponse GetRawMessageContent =
      GetRawMessageContentResponse
  request :: GetRawMessageContent -> Request GetRawMessageContent
request = Service -> GetRawMessageContent -> Request GetRawMessageContent
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetRawMessageContent
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetRawMessageContent)))
response =
    (Int
 -> ResponseHeaders
 -> ResponseBody
 -> Either String (AWSResponse GetRawMessageContent))
-> Logger
-> Service
-> Proxy GetRawMessageContent
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetRawMessageContent)))
forall (m :: * -> *) a.
MonadResource m =>
(Int
 -> ResponseHeaders
 -> ResponseBody
 -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveBody
      ( \Int
s ResponseHeaders
h ResponseBody
x ->
          Int -> ResponseBody -> GetRawMessageContentResponse
GetRawMessageContentResponse'
            (Int -> ResponseBody -> GetRawMessageContentResponse)
-> Either String Int
-> Either String (ResponseBody -> GetRawMessageContentResponse)
forall (f :: * -> *) a b. Functor 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))
            Either String (ResponseBody -> GetRawMessageContentResponse)
-> Either String ResponseBody
-> Either String GetRawMessageContentResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (ResponseBody -> Either String ResponseBody
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure ResponseBody
x)
      )

instance Prelude.Hashable GetRawMessageContent

instance Prelude.NFData GetRawMessageContent

instance Core.ToHeaders GetRawMessageContent where
  toHeaders :: GetRawMessageContent -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetRawMessageContent -> 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 GetRawMessageContent where
  toPath :: GetRawMessageContent -> ByteString
toPath GetRawMessageContent' {Text
messageId :: Text
$sel:messageId:GetRawMessageContent' :: GetRawMessageContent -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/messages/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
messageId]

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

-- | /See:/ 'newGetRawMessageContentResponse' smart constructor.
data GetRawMessageContentResponse = GetRawMessageContentResponse'
  { -- | The response's http status code.
    GetRawMessageContentResponse -> Int
httpStatus :: Prelude.Int,
    -- | The raw content of the email message, in MIME format.
    GetRawMessageContentResponse -> ResponseBody
messageContent :: Core.ResponseBody
  }
  deriving (Int -> GetRawMessageContentResponse -> ShowS
[GetRawMessageContentResponse] -> ShowS
GetRawMessageContentResponse -> String
(Int -> GetRawMessageContentResponse -> ShowS)
-> (GetRawMessageContentResponse -> String)
-> ([GetRawMessageContentResponse] -> ShowS)
-> Show GetRawMessageContentResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRawMessageContentResponse] -> ShowS
$cshowList :: [GetRawMessageContentResponse] -> ShowS
show :: GetRawMessageContentResponse -> String
$cshow :: GetRawMessageContentResponse -> String
showsPrec :: Int -> GetRawMessageContentResponse -> ShowS
$cshowsPrec :: Int -> GetRawMessageContentResponse -> ShowS
Prelude.Show, (forall x.
 GetRawMessageContentResponse -> Rep GetRawMessageContentResponse x)
-> (forall x.
    Rep GetRawMessageContentResponse x -> GetRawMessageContentResponse)
-> Generic GetRawMessageContentResponse
forall x.
Rep GetRawMessageContentResponse x -> GetRawMessageContentResponse
forall x.
GetRawMessageContentResponse -> Rep GetRawMessageContentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetRawMessageContentResponse x -> GetRawMessageContentResponse
$cfrom :: forall x.
GetRawMessageContentResponse -> Rep GetRawMessageContentResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetRawMessageContentResponse' 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:
--
-- 'httpStatus', 'getRawMessageContentResponse_httpStatus' - The response's http status code.
--
-- 'messageContent', 'getRawMessageContentResponse_messageContent' - The raw content of the email message, in MIME format.
newGetRawMessageContentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'messageContent'
  Core.ResponseBody ->
  GetRawMessageContentResponse
newGetRawMessageContentResponse :: Int -> ResponseBody -> GetRawMessageContentResponse
newGetRawMessageContentResponse
  Int
pHttpStatus_
  ResponseBody
pMessageContent_ =
    GetRawMessageContentResponse' :: Int -> ResponseBody -> GetRawMessageContentResponse
GetRawMessageContentResponse'
      { $sel:httpStatus:GetRawMessageContentResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:messageContent:GetRawMessageContentResponse' :: ResponseBody
messageContent = ResponseBody
pMessageContent_
      }

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

-- | The raw content of the email message, in MIME format.
getRawMessageContentResponse_messageContent :: Lens.Lens' GetRawMessageContentResponse Core.ResponseBody
getRawMessageContentResponse_messageContent :: (ResponseBody -> f ResponseBody)
-> GetRawMessageContentResponse -> f GetRawMessageContentResponse
getRawMessageContentResponse_messageContent = (GetRawMessageContentResponse -> ResponseBody)
-> (GetRawMessageContentResponse
    -> ResponseBody -> GetRawMessageContentResponse)
-> Lens
     GetRawMessageContentResponse
     GetRawMessageContentResponse
     ResponseBody
     ResponseBody
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRawMessageContentResponse' {ResponseBody
messageContent :: ResponseBody
$sel:messageContent:GetRawMessageContentResponse' :: GetRawMessageContentResponse -> ResponseBody
messageContent} -> ResponseBody
messageContent) (\s :: GetRawMessageContentResponse
s@GetRawMessageContentResponse' {} ResponseBody
a -> GetRawMessageContentResponse
s {$sel:messageContent:GetRawMessageContentResponse' :: ResponseBody
messageContent = ResponseBody
a} :: GetRawMessageContentResponse)