{-# 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.Pinpoint.SendUsersMessages
-- 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)
--
-- Creates and sends a message to a list of users.
module Amazonka.Pinpoint.SendUsersMessages
  ( -- * Creating a Request
    SendUsersMessages (..),
    newSendUsersMessages,

    -- * Request Lenses
    sendUsersMessages_applicationId,
    sendUsersMessages_sendUsersMessageRequest,

    -- * Destructuring the Response
    SendUsersMessagesResponse (..),
    newSendUsersMessagesResponse,

    -- * Response Lenses
    sendUsersMessagesResponse_httpStatus,
    sendUsersMessagesResponse_sendUsersMessageResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newSendUsersMessages' smart constructor.
data SendUsersMessages = SendUsersMessages'
  { -- | The unique identifier for the application. This identifier is displayed
    -- as the __Project ID__ on the Amazon Pinpoint console.
    SendUsersMessages -> Text
applicationId :: Prelude.Text,
    SendUsersMessages -> SendUsersMessageRequest
sendUsersMessageRequest :: SendUsersMessageRequest
  }
  deriving (SendUsersMessages -> SendUsersMessages -> Bool
(SendUsersMessages -> SendUsersMessages -> Bool)
-> (SendUsersMessages -> SendUsersMessages -> Bool)
-> Eq SendUsersMessages
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendUsersMessages -> SendUsersMessages -> Bool
$c/= :: SendUsersMessages -> SendUsersMessages -> Bool
== :: SendUsersMessages -> SendUsersMessages -> Bool
$c== :: SendUsersMessages -> SendUsersMessages -> Bool
Prelude.Eq, ReadPrec [SendUsersMessages]
ReadPrec SendUsersMessages
Int -> ReadS SendUsersMessages
ReadS [SendUsersMessages]
(Int -> ReadS SendUsersMessages)
-> ReadS [SendUsersMessages]
-> ReadPrec SendUsersMessages
-> ReadPrec [SendUsersMessages]
-> Read SendUsersMessages
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SendUsersMessages]
$creadListPrec :: ReadPrec [SendUsersMessages]
readPrec :: ReadPrec SendUsersMessages
$creadPrec :: ReadPrec SendUsersMessages
readList :: ReadS [SendUsersMessages]
$creadList :: ReadS [SendUsersMessages]
readsPrec :: Int -> ReadS SendUsersMessages
$creadsPrec :: Int -> ReadS SendUsersMessages
Prelude.Read, Int -> SendUsersMessages -> ShowS
[SendUsersMessages] -> ShowS
SendUsersMessages -> String
(Int -> SendUsersMessages -> ShowS)
-> (SendUsersMessages -> String)
-> ([SendUsersMessages] -> ShowS)
-> Show SendUsersMessages
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendUsersMessages] -> ShowS
$cshowList :: [SendUsersMessages] -> ShowS
show :: SendUsersMessages -> String
$cshow :: SendUsersMessages -> String
showsPrec :: Int -> SendUsersMessages -> ShowS
$cshowsPrec :: Int -> SendUsersMessages -> ShowS
Prelude.Show, (forall x. SendUsersMessages -> Rep SendUsersMessages x)
-> (forall x. Rep SendUsersMessages x -> SendUsersMessages)
-> Generic SendUsersMessages
forall x. Rep SendUsersMessages x -> SendUsersMessages
forall x. SendUsersMessages -> Rep SendUsersMessages x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendUsersMessages x -> SendUsersMessages
$cfrom :: forall x. SendUsersMessages -> Rep SendUsersMessages x
Prelude.Generic)

-- |
-- Create a value of 'SendUsersMessages' 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:
--
-- 'applicationId', 'sendUsersMessages_applicationId' - The unique identifier for the application. This identifier is displayed
-- as the __Project ID__ on the Amazon Pinpoint console.
--
-- 'sendUsersMessageRequest', 'sendUsersMessages_sendUsersMessageRequest' - Undocumented member.
newSendUsersMessages ::
  -- | 'applicationId'
  Prelude.Text ->
  -- | 'sendUsersMessageRequest'
  SendUsersMessageRequest ->
  SendUsersMessages
newSendUsersMessages :: Text -> SendUsersMessageRequest -> SendUsersMessages
newSendUsersMessages
  Text
pApplicationId_
  SendUsersMessageRequest
pSendUsersMessageRequest_ =
    SendUsersMessages' :: Text -> SendUsersMessageRequest -> SendUsersMessages
SendUsersMessages'
      { $sel:applicationId:SendUsersMessages' :: Text
applicationId = Text
pApplicationId_,
        $sel:sendUsersMessageRequest:SendUsersMessages' :: SendUsersMessageRequest
sendUsersMessageRequest = SendUsersMessageRequest
pSendUsersMessageRequest_
      }

-- | The unique identifier for the application. This identifier is displayed
-- as the __Project ID__ on the Amazon Pinpoint console.
sendUsersMessages_applicationId :: Lens.Lens' SendUsersMessages Prelude.Text
sendUsersMessages_applicationId :: (Text -> f Text) -> SendUsersMessages -> f SendUsersMessages
sendUsersMessages_applicationId = (SendUsersMessages -> Text)
-> (SendUsersMessages -> Text -> SendUsersMessages)
-> Lens SendUsersMessages SendUsersMessages Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendUsersMessages' {Text
applicationId :: Text
$sel:applicationId:SendUsersMessages' :: SendUsersMessages -> Text
applicationId} -> Text
applicationId) (\s :: SendUsersMessages
s@SendUsersMessages' {} Text
a -> SendUsersMessages
s {$sel:applicationId:SendUsersMessages' :: Text
applicationId = Text
a} :: SendUsersMessages)

-- | Undocumented member.
sendUsersMessages_sendUsersMessageRequest :: Lens.Lens' SendUsersMessages SendUsersMessageRequest
sendUsersMessages_sendUsersMessageRequest :: (SendUsersMessageRequest -> f SendUsersMessageRequest)
-> SendUsersMessages -> f SendUsersMessages
sendUsersMessages_sendUsersMessageRequest = (SendUsersMessages -> SendUsersMessageRequest)
-> (SendUsersMessages
    -> SendUsersMessageRequest -> SendUsersMessages)
-> Lens
     SendUsersMessages
     SendUsersMessages
     SendUsersMessageRequest
     SendUsersMessageRequest
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendUsersMessages' {SendUsersMessageRequest
sendUsersMessageRequest :: SendUsersMessageRequest
$sel:sendUsersMessageRequest:SendUsersMessages' :: SendUsersMessages -> SendUsersMessageRequest
sendUsersMessageRequest} -> SendUsersMessageRequest
sendUsersMessageRequest) (\s :: SendUsersMessages
s@SendUsersMessages' {} SendUsersMessageRequest
a -> SendUsersMessages
s {$sel:sendUsersMessageRequest:SendUsersMessages' :: SendUsersMessageRequest
sendUsersMessageRequest = SendUsersMessageRequest
a} :: SendUsersMessages)

instance Core.AWSRequest SendUsersMessages where
  type
    AWSResponse SendUsersMessages =
      SendUsersMessagesResponse
  request :: SendUsersMessages -> Request SendUsersMessages
request = Service -> SendUsersMessages -> Request SendUsersMessages
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy SendUsersMessages
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SendUsersMessages)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse SendUsersMessages))
-> Logger
-> Service
-> Proxy SendUsersMessages
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SendUsersMessages)))
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 ->
          Int -> SendUsersMessageResponse -> SendUsersMessagesResponse
SendUsersMessagesResponse'
            (Int -> SendUsersMessageResponse -> SendUsersMessagesResponse)
-> Either String Int
-> Either
     String (SendUsersMessageResponse -> SendUsersMessagesResponse)
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 (SendUsersMessageResponse -> SendUsersMessagesResponse)
-> Either String SendUsersMessageResponse
-> Either String SendUsersMessagesResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object -> Either String SendUsersMessageResponse
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)
      )

instance Prelude.Hashable SendUsersMessages

instance Prelude.NFData SendUsersMessages

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

instance Core.ToPath SendUsersMessages where
  toPath :: SendUsersMessages -> ByteString
toPath SendUsersMessages' {Text
SendUsersMessageRequest
sendUsersMessageRequest :: SendUsersMessageRequest
applicationId :: Text
$sel:sendUsersMessageRequest:SendUsersMessages' :: SendUsersMessages -> SendUsersMessageRequest
$sel:applicationId:SendUsersMessages' :: SendUsersMessages -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/v1/apps/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
applicationId,
        ByteString
"/users-messages"
      ]

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

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

-- |
-- Create a value of 'SendUsersMessagesResponse' 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', 'sendUsersMessagesResponse_httpStatus' - The response's http status code.
--
-- 'sendUsersMessageResponse', 'sendUsersMessagesResponse_sendUsersMessageResponse' - Undocumented member.
newSendUsersMessagesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'sendUsersMessageResponse'
  SendUsersMessageResponse ->
  SendUsersMessagesResponse
newSendUsersMessagesResponse :: Int -> SendUsersMessageResponse -> SendUsersMessagesResponse
newSendUsersMessagesResponse
  Int
pHttpStatus_
  SendUsersMessageResponse
pSendUsersMessageResponse_ =
    SendUsersMessagesResponse' :: Int -> SendUsersMessageResponse -> SendUsersMessagesResponse
SendUsersMessagesResponse'
      { $sel:httpStatus:SendUsersMessagesResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:sendUsersMessageResponse:SendUsersMessagesResponse' :: SendUsersMessageResponse
sendUsersMessageResponse =
          SendUsersMessageResponse
pSendUsersMessageResponse_
      }

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

-- | Undocumented member.
sendUsersMessagesResponse_sendUsersMessageResponse :: Lens.Lens' SendUsersMessagesResponse SendUsersMessageResponse
sendUsersMessagesResponse_sendUsersMessageResponse :: (SendUsersMessageResponse -> f SendUsersMessageResponse)
-> SendUsersMessagesResponse -> f SendUsersMessagesResponse
sendUsersMessagesResponse_sendUsersMessageResponse = (SendUsersMessagesResponse -> SendUsersMessageResponse)
-> (SendUsersMessagesResponse
    -> SendUsersMessageResponse -> SendUsersMessagesResponse)
-> Lens
     SendUsersMessagesResponse
     SendUsersMessagesResponse
     SendUsersMessageResponse
     SendUsersMessageResponse
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendUsersMessagesResponse' {SendUsersMessageResponse
sendUsersMessageResponse :: SendUsersMessageResponse
$sel:sendUsersMessageResponse:SendUsersMessagesResponse' :: SendUsersMessagesResponse -> SendUsersMessageResponse
sendUsersMessageResponse} -> SendUsersMessageResponse
sendUsersMessageResponse) (\s :: SendUsersMessagesResponse
s@SendUsersMessagesResponse' {} SendUsersMessageResponse
a -> SendUsersMessagesResponse
s {$sel:sendUsersMessageResponse:SendUsersMessagesResponse' :: SendUsersMessageResponse
sendUsersMessageResponse = SendUsersMessageResponse
a} :: SendUsersMessagesResponse)

instance Prelude.NFData SendUsersMessagesResponse