{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $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 :: Lens' PutRawMessageContent Text
putRawMessageContent_messageId = 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 :: Lens' PutRawMessageContent RawMessageContent
putRawMessageContent_content = 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 :: (Service -> Service)
-> PutRawMessageContent -> Request PutRawMessageContent
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutRawMessageContent
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRawMessageContent)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PutRawMessageContentResponse
PutRawMessageContentResponse'
            forall (f :: * -> *) a b. Functor 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 PutRawMessageContent where
  hashWithSalt :: Int -> PutRawMessageContent -> Int
hashWithSalt Int
_salt PutRawMessageContent' {Text
RawMessageContent
content :: RawMessageContent
messageId :: Text
$sel:content:PutRawMessageContent' :: PutRawMessageContent -> RawMessageContent
$sel:messageId:PutRawMessageContent' :: PutRawMessageContent -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
messageId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` RawMessageContent
content

instance Prelude.NFData PutRawMessageContent where
  rnf :: PutRawMessageContent -> ()
rnf PutRawMessageContent' {Text
RawMessageContent
content :: RawMessageContent
messageId :: Text
$sel:content:PutRawMessageContent' :: PutRawMessageContent -> RawMessageContent
$sel:messageId:PutRawMessageContent' :: PutRawMessageContent -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
messageId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf RawMessageContent
content

instance Data.ToHeaders PutRawMessageContent where
  toHeaders :: PutRawMessageContent -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"content" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= RawMessageContent
content)]
      )

instance Data.ToPath PutRawMessageContent where
  toPath :: PutRawMessageContent -> ByteString
toPath PutRawMessageContent' {Text
RawMessageContent
content :: RawMessageContent
messageId :: Text
$sel:content:PutRawMessageContent' :: PutRawMessageContent -> RawMessageContent
$sel:messageId:PutRawMessageContent' :: PutRawMessageContent -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/messages/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
messageId]

instance Data.ToQuery PutRawMessageContent where
  toQuery :: PutRawMessageContent -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:httpStatus:PutRawMessageContentResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
putRawMessageContentResponse_httpStatus :: Lens.Lens' PutRawMessageContentResponse Prelude.Int
putRawMessageContentResponse_httpStatus :: Lens' PutRawMessageContentResponse Int
putRawMessageContentResponse_httpStatus = 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 where
  rnf :: PutRawMessageContentResponse -> ()
rnf PutRawMessageContentResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutRawMessageContentResponse' :: PutRawMessageContentResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus