{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SNS.Types.MessageAttributeValue
-- 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)
module Amazonka.SNS.Types.MessageAttributeValue where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The user-specified message attribute value. For string data types, the
-- value attribute has the same restrictions on the content as the message
-- body. For more information, see
-- <https://docs.aws.amazon.com/sns/latest/api/API_Publish.html Publish>.
--
-- Name, type, and value must not be empty or null. In addition, the
-- message body should not be empty or null. All parts of the message
-- attribute, including name, type, and value, are included in the message
-- size restriction, which is currently 256 KB (262,144 bytes). For more
-- information, see
-- <https://docs.aws.amazon.com/sns/latest/dg/SNSMessageAttributes.html Amazon SNS message attributes>
-- and
-- <https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html Publishing to a mobile phone>
-- in the /Amazon SNS Developer Guide./
--
-- /See:/ 'newMessageAttributeValue' smart constructor.
data MessageAttributeValue = MessageAttributeValue'
  { -- | Binary type attributes can store any binary data, for example,
    -- compressed data, encrypted data, or images.
    MessageAttributeValue -> Maybe Base64
binaryValue :: Prelude.Maybe Core.Base64,
    -- | Strings are Unicode with UTF8 binary encoding. For a list of code
    -- values, see
    -- <https://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters ASCII Printable Characters>.
    MessageAttributeValue -> Maybe Text
stringValue :: Prelude.Maybe Prelude.Text,
    -- | Amazon SNS supports the following logical data types: String,
    -- String.Array, Number, and Binary. For more information, see
    -- <https://docs.aws.amazon.com/sns/latest/dg/SNSMessageAttributes.html#SNSMessageAttributes.DataTypes Message Attribute Data Types>.
    MessageAttributeValue -> Text
dataType :: Prelude.Text
  }
  deriving (MessageAttributeValue -> MessageAttributeValue -> Bool
(MessageAttributeValue -> MessageAttributeValue -> Bool)
-> (MessageAttributeValue -> MessageAttributeValue -> Bool)
-> Eq MessageAttributeValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MessageAttributeValue -> MessageAttributeValue -> Bool
$c/= :: MessageAttributeValue -> MessageAttributeValue -> Bool
== :: MessageAttributeValue -> MessageAttributeValue -> Bool
$c== :: MessageAttributeValue -> MessageAttributeValue -> Bool
Prelude.Eq, ReadPrec [MessageAttributeValue]
ReadPrec MessageAttributeValue
Int -> ReadS MessageAttributeValue
ReadS [MessageAttributeValue]
(Int -> ReadS MessageAttributeValue)
-> ReadS [MessageAttributeValue]
-> ReadPrec MessageAttributeValue
-> ReadPrec [MessageAttributeValue]
-> Read MessageAttributeValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MessageAttributeValue]
$creadListPrec :: ReadPrec [MessageAttributeValue]
readPrec :: ReadPrec MessageAttributeValue
$creadPrec :: ReadPrec MessageAttributeValue
readList :: ReadS [MessageAttributeValue]
$creadList :: ReadS [MessageAttributeValue]
readsPrec :: Int -> ReadS MessageAttributeValue
$creadsPrec :: Int -> ReadS MessageAttributeValue
Prelude.Read, Int -> MessageAttributeValue -> ShowS
[MessageAttributeValue] -> ShowS
MessageAttributeValue -> String
(Int -> MessageAttributeValue -> ShowS)
-> (MessageAttributeValue -> String)
-> ([MessageAttributeValue] -> ShowS)
-> Show MessageAttributeValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MessageAttributeValue] -> ShowS
$cshowList :: [MessageAttributeValue] -> ShowS
show :: MessageAttributeValue -> String
$cshow :: MessageAttributeValue -> String
showsPrec :: Int -> MessageAttributeValue -> ShowS
$cshowsPrec :: Int -> MessageAttributeValue -> ShowS
Prelude.Show, (forall x. MessageAttributeValue -> Rep MessageAttributeValue x)
-> (forall x. Rep MessageAttributeValue x -> MessageAttributeValue)
-> Generic MessageAttributeValue
forall x. Rep MessageAttributeValue x -> MessageAttributeValue
forall x. MessageAttributeValue -> Rep MessageAttributeValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MessageAttributeValue x -> MessageAttributeValue
$cfrom :: forall x. MessageAttributeValue -> Rep MessageAttributeValue x
Prelude.Generic)

-- |
-- Create a value of 'MessageAttributeValue' 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:
--
-- 'binaryValue', 'messageAttributeValue_binaryValue' - Binary type attributes can store any binary data, for example,
-- compressed data, encrypted data, or images.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
--
-- 'stringValue', 'messageAttributeValue_stringValue' - Strings are Unicode with UTF8 binary encoding. For a list of code
-- values, see
-- <https://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters ASCII Printable Characters>.
--
-- 'dataType', 'messageAttributeValue_dataType' - Amazon SNS supports the following logical data types: String,
-- String.Array, Number, and Binary. For more information, see
-- <https://docs.aws.amazon.com/sns/latest/dg/SNSMessageAttributes.html#SNSMessageAttributes.DataTypes Message Attribute Data Types>.
newMessageAttributeValue ::
  -- | 'dataType'
  Prelude.Text ->
  MessageAttributeValue
newMessageAttributeValue :: Text -> MessageAttributeValue
newMessageAttributeValue Text
pDataType_ =
  MessageAttributeValue' :: Maybe Base64 -> Maybe Text -> Text -> MessageAttributeValue
MessageAttributeValue'
    { $sel:binaryValue:MessageAttributeValue' :: Maybe Base64
binaryValue =
        Maybe Base64
forall a. Maybe a
Prelude.Nothing,
      $sel:stringValue:MessageAttributeValue' :: Maybe Text
stringValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:dataType:MessageAttributeValue' :: Text
dataType = Text
pDataType_
    }

-- | Binary type attributes can store any binary data, for example,
-- compressed data, encrypted data, or images.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
messageAttributeValue_binaryValue :: Lens.Lens' MessageAttributeValue (Prelude.Maybe Prelude.ByteString)
messageAttributeValue_binaryValue :: (Maybe ByteString -> f (Maybe ByteString))
-> MessageAttributeValue -> f MessageAttributeValue
messageAttributeValue_binaryValue = (MessageAttributeValue -> Maybe Base64)
-> (MessageAttributeValue -> Maybe Base64 -> MessageAttributeValue)
-> Lens
     MessageAttributeValue
     MessageAttributeValue
     (Maybe Base64)
     (Maybe Base64)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageAttributeValue' {Maybe Base64
binaryValue :: Maybe Base64
$sel:binaryValue:MessageAttributeValue' :: MessageAttributeValue -> Maybe Base64
binaryValue} -> Maybe Base64
binaryValue) (\s :: MessageAttributeValue
s@MessageAttributeValue' {} Maybe Base64
a -> MessageAttributeValue
s {$sel:binaryValue:MessageAttributeValue' :: Maybe Base64
binaryValue = Maybe Base64
a} :: MessageAttributeValue) ((Maybe Base64 -> f (Maybe Base64))
 -> MessageAttributeValue -> f MessageAttributeValue)
-> ((Maybe ByteString -> f (Maybe ByteString))
    -> Maybe Base64 -> f (Maybe Base64))
-> (Maybe ByteString -> f (Maybe ByteString))
-> MessageAttributeValue
-> f MessageAttributeValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso Base64 Base64 ByteString ByteString
-> Iso
     (Maybe Base64) (Maybe Base64) (Maybe ByteString) (Maybe ByteString)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso Base64 Base64 ByteString ByteString
Iso' Base64 ByteString
Core._Base64

-- | Strings are Unicode with UTF8 binary encoding. For a list of code
-- values, see
-- <https://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters ASCII Printable Characters>.
messageAttributeValue_stringValue :: Lens.Lens' MessageAttributeValue (Prelude.Maybe Prelude.Text)
messageAttributeValue_stringValue :: (Maybe Text -> f (Maybe Text))
-> MessageAttributeValue -> f MessageAttributeValue
messageAttributeValue_stringValue = (MessageAttributeValue -> Maybe Text)
-> (MessageAttributeValue -> Maybe Text -> MessageAttributeValue)
-> Lens
     MessageAttributeValue
     MessageAttributeValue
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageAttributeValue' {Maybe Text
stringValue :: Maybe Text
$sel:stringValue:MessageAttributeValue' :: MessageAttributeValue -> Maybe Text
stringValue} -> Maybe Text
stringValue) (\s :: MessageAttributeValue
s@MessageAttributeValue' {} Maybe Text
a -> MessageAttributeValue
s {$sel:stringValue:MessageAttributeValue' :: Maybe Text
stringValue = Maybe Text
a} :: MessageAttributeValue)

-- | Amazon SNS supports the following logical data types: String,
-- String.Array, Number, and Binary. For more information, see
-- <https://docs.aws.amazon.com/sns/latest/dg/SNSMessageAttributes.html#SNSMessageAttributes.DataTypes Message Attribute Data Types>.
messageAttributeValue_dataType :: Lens.Lens' MessageAttributeValue Prelude.Text
messageAttributeValue_dataType :: (Text -> f Text)
-> MessageAttributeValue -> f MessageAttributeValue
messageAttributeValue_dataType = (MessageAttributeValue -> Text)
-> (MessageAttributeValue -> Text -> MessageAttributeValue)
-> Lens MessageAttributeValue MessageAttributeValue Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageAttributeValue' {Text
dataType :: Text
$sel:dataType:MessageAttributeValue' :: MessageAttributeValue -> Text
dataType} -> Text
dataType) (\s :: MessageAttributeValue
s@MessageAttributeValue' {} Text
a -> MessageAttributeValue
s {$sel:dataType:MessageAttributeValue' :: Text
dataType = Text
a} :: MessageAttributeValue)

instance Prelude.Hashable MessageAttributeValue

instance Prelude.NFData MessageAttributeValue

instance Core.ToQuery MessageAttributeValue where
  toQuery :: MessageAttributeValue -> QueryString
toQuery MessageAttributeValue' {Maybe Text
Maybe Base64
Text
dataType :: Text
stringValue :: Maybe Text
binaryValue :: Maybe Base64
$sel:dataType:MessageAttributeValue' :: MessageAttributeValue -> Text
$sel:stringValue:MessageAttributeValue' :: MessageAttributeValue -> Maybe Text
$sel:binaryValue:MessageAttributeValue' :: MessageAttributeValue -> Maybe Base64
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"BinaryValue" ByteString -> Maybe Base64 -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Base64
binaryValue,
        ByteString
"StringValue" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
stringValue,
        ByteString
"DataType" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
dataType
      ]