{-# 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.PutRawMessageContent
-- 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)
--
-- Updates the raw content of an in-transit email message, in MIME format.
--
-- This example describes how to update in-transit email message. For more
-- information and examples for using this API, see
-- <https://docs.aws.amazon.com/workmail/latest/adminguide/update-with-lambda.html Updating message content with AWS Lambda>.
--
-- Updates to an in-transit message only appear when you call
-- @PutRawMessageContent@ from an AWS Lambda function configured with a
-- synchronous
-- <https://docs.aws.amazon.com/workmail/latest/adminguide/lambda.html#synchronous-rules Run Lambda>
-- rule. If you call @PutRawMessageContent@ on a delivered or sent message,
-- the message remains unchanged, even though
-- <https://docs.aws.amazon.com/workmail/latest/APIReference/API_messageflow_GetRawMessageContent.html GetRawMessageContent>
-- returns an updated message.
module Amazonka.WorkMailMessageFlow.PutRawMessageContent
  ( -- * Creating a Request
    PutRawMessageContent (..),
    newPutRawMessageContent,

    -- * Request Lenses
    putRawMessageContent_messageId,
    putRawMessageContent_content,

    -- * Destructuring the Response
    PutRawMessageContentResponse (..),
    newPutRawMessageContentResponse,

    -- * Response Lenses
    putRawMessageContentResponse_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.WorkMailMessageFlow.Types

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

-- |
-- Create a value of 'PutRawMessageContent' 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', 'putRawMessageContent_messageId' - The identifier of the email message being updated.
--
-- 'content', 'putRawMessageContent_content' - Describes the raw message content of the updated email message.
newPutRawMessageContent ::
  -- | 'messageId'
  Prelude.Text ->
  -- | 'content'
  RawMessageContent ->
  PutRawMessageContent
newPutRawMessageContent :: Text -> RawMessageContent -> PutRawMessageContent
newPutRawMessageContent Text
pMessageId_ RawMessageContent
pContent_ =
  PutRawMessageContent' :: Text -> RawMessageContent -> PutRawMessageContent
PutRawMessageContent'
    { $sel:messageId:PutRawMessageContent' :: Text
messageId = Text
pMessageId_,
      $sel:content:PutRawMessageContent' :: RawMessageContent
content = RawMessageContent
pContent_
    }

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

-- | Describes the raw message content of the updated email message.
putRawMessageContent_content :: Lens.Lens' PutRawMessageContent RawMessageContent
putRawMessageContent_content :: (RawMessageContent -> f RawMessageContent)
-> PutRawMessageContent -> f PutRawMessageContent
putRawMessageContent_content = (PutRawMessageContent -> RawMessageContent)
-> (PutRawMessageContent
    -> RawMessageContent -> PutRawMessageContent)
-> Lens
     PutRawMessageContent
     PutRawMessageContent
     RawMessageContent
     RawMessageContent
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRawMessageContent' {RawMessageContent
content :: RawMessageContent
$sel:content:PutRawMessageContent' :: PutRawMessageContent -> RawMessageContent
content} -> RawMessageContent
content) (\s :: PutRawMessageContent
s@PutRawMessageContent' {} RawMessageContent
a -> PutRawMessageContent
s {$sel:content:PutRawMessageContent' :: RawMessageContent
content = RawMessageContent
a} :: PutRawMessageContent)

instance Core.AWSRequest PutRawMessageContent where
  type
    AWSResponse PutRawMessageContent =
      PutRawMessageContentResponse
  request :: PutRawMessageContent -> Request PutRawMessageContent
request = Service -> PutRawMessageContent -> Request PutRawMessageContent
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutRawMessageContent
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRawMessageContent)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse PutRawMessageContent))
-> Logger
-> Service
-> Proxy PutRawMessageContent
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRawMessageContent)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PutRawMessageContentResponse
PutRawMessageContentResponse'
            (Int -> PutRawMessageContentResponse)
-> Either String Int -> Either String PutRawMessageContentResponse
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))
      )

instance Prelude.Hashable PutRawMessageContent

instance Prelude.NFData PutRawMessageContent

instance Core.ToHeaders PutRawMessageContent where
  toHeaders :: PutRawMessageContent -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutRawMessageContent -> 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.ToJSON PutRawMessageContent where
  toJSON :: PutRawMessageContent -> Value
toJSON PutRawMessageContent' {Text
RawMessageContent
content :: RawMessageContent
messageId :: Text
$sel:content:PutRawMessageContent' :: PutRawMessageContent -> RawMessageContent
$sel:messageId:PutRawMessageContent' :: PutRawMessageContent -> 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
"content" Text -> RawMessageContent -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RawMessageContent
content)]
      )

instance Core.ToPath PutRawMessageContent where
  toPath :: PutRawMessageContent -> ByteString
toPath PutRawMessageContent' {Text
RawMessageContent
content :: RawMessageContent
messageId :: Text
$sel:content:PutRawMessageContent' :: PutRawMessageContent -> RawMessageContent
$sel:messageId:PutRawMessageContent' :: PutRawMessageContent -> 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 PutRawMessageContent where
  toQuery :: PutRawMessageContent -> QueryString
toQuery = QueryString -> PutRawMessageContent -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

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

-- |
-- Create a value of 'PutRawMessageContentResponse' 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', 'putRawMessageContentResponse_httpStatus' - The response's http status code.
newPutRawMessageContentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutRawMessageContentResponse
newPutRawMessageContentResponse :: Int -> PutRawMessageContentResponse
newPutRawMessageContentResponse Int
pHttpStatus_ =
  PutRawMessageContentResponse' :: Int -> PutRawMessageContentResponse
PutRawMessageContentResponse'
    { $sel:httpStatus:PutRawMessageContentResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData PutRawMessageContentResponse