{-# 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.LexModels.Types.Message
-- 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.LexModels.Types.Message where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.LexModels.Types.ContentType
import qualified Amazonka.Prelude as Prelude

-- | The message object that provides the message text and its type.
--
-- /See:/ 'newMessage' smart constructor.
data Message = Message'
  { -- | Identifies the message group that the message belongs to. When a group
    -- is assigned to a message, Amazon Lex returns one message from each group
    -- in the response.
    Message -> Maybe Natural
groupNumber :: Prelude.Maybe Prelude.Natural,
    -- | The content type of the message string.
    Message -> ContentType
contentType :: ContentType,
    -- | The text of the message.
    Message -> Text
content :: Prelude.Text
  }
  deriving (Message -> Message -> Bool
(Message -> Message -> Bool)
-> (Message -> Message -> Bool) -> Eq Message
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Message -> Message -> Bool
$c/= :: Message -> Message -> Bool
== :: Message -> Message -> Bool
$c== :: Message -> Message -> Bool
Prelude.Eq, ReadPrec [Message]
ReadPrec Message
Int -> ReadS Message
ReadS [Message]
(Int -> ReadS Message)
-> ReadS [Message]
-> ReadPrec Message
-> ReadPrec [Message]
-> Read Message
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Message]
$creadListPrec :: ReadPrec [Message]
readPrec :: ReadPrec Message
$creadPrec :: ReadPrec Message
readList :: ReadS [Message]
$creadList :: ReadS [Message]
readsPrec :: Int -> ReadS Message
$creadsPrec :: Int -> ReadS Message
Prelude.Read, Int -> Message -> ShowS
[Message] -> ShowS
Message -> String
(Int -> Message -> ShowS)
-> (Message -> String) -> ([Message] -> ShowS) -> Show Message
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Message] -> ShowS
$cshowList :: [Message] -> ShowS
show :: Message -> String
$cshow :: Message -> String
showsPrec :: Int -> Message -> ShowS
$cshowsPrec :: Int -> Message -> ShowS
Prelude.Show, (forall x. Message -> Rep Message x)
-> (forall x. Rep Message x -> Message) -> Generic Message
forall x. Rep Message x -> Message
forall x. Message -> Rep Message x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Message x -> Message
$cfrom :: forall x. Message -> Rep Message x
Prelude.Generic)

-- |
-- Create a value of 'Message' 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:
--
-- 'groupNumber', 'message_groupNumber' - Identifies the message group that the message belongs to. When a group
-- is assigned to a message, Amazon Lex returns one message from each group
-- in the response.
--
-- 'contentType', 'message_contentType' - The content type of the message string.
--
-- 'content', 'message_content' - The text of the message.
newMessage ::
  -- | 'contentType'
  ContentType ->
  -- | 'content'
  Prelude.Text ->
  Message
newMessage :: ContentType -> Text -> Message
newMessage ContentType
pContentType_ Text
pContent_ =
  Message' :: Maybe Natural -> ContentType -> Text -> Message
Message'
    { $sel:groupNumber:Message' :: Maybe Natural
groupNumber = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:contentType:Message' :: ContentType
contentType = ContentType
pContentType_,
      $sel:content:Message' :: Text
content = Text
pContent_
    }

-- | Identifies the message group that the message belongs to. When a group
-- is assigned to a message, Amazon Lex returns one message from each group
-- in the response.
message_groupNumber :: Lens.Lens' Message (Prelude.Maybe Prelude.Natural)
message_groupNumber :: (Maybe Natural -> f (Maybe Natural)) -> Message -> f Message
message_groupNumber = (Message -> Maybe Natural)
-> (Message -> Maybe Natural -> Message)
-> Lens Message Message (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Maybe Natural
groupNumber :: Maybe Natural
$sel:groupNumber:Message' :: Message -> Maybe Natural
groupNumber} -> Maybe Natural
groupNumber) (\s :: Message
s@Message' {} Maybe Natural
a -> Message
s {$sel:groupNumber:Message' :: Maybe Natural
groupNumber = Maybe Natural
a} :: Message)

-- | The content type of the message string.
message_contentType :: Lens.Lens' Message ContentType
message_contentType :: (ContentType -> f ContentType) -> Message -> f Message
message_contentType = (Message -> ContentType)
-> (Message -> ContentType -> Message)
-> Lens Message Message ContentType ContentType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {ContentType
contentType :: ContentType
$sel:contentType:Message' :: Message -> ContentType
contentType} -> ContentType
contentType) (\s :: Message
s@Message' {} ContentType
a -> Message
s {$sel:contentType:Message' :: ContentType
contentType = ContentType
a} :: Message)

-- | The text of the message.
message_content :: Lens.Lens' Message Prelude.Text
message_content :: (Text -> f Text) -> Message -> f Message
message_content = (Message -> Text)
-> (Message -> Text -> Message) -> Lens Message Message Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Message' {Text
content :: Text
$sel:content:Message' :: Message -> Text
content} -> Text
content) (\s :: Message
s@Message' {} Text
a -> Message
s {$sel:content:Message' :: Text
content = Text
a} :: Message)

instance Core.FromJSON Message where
  parseJSON :: Value -> Parser Message
parseJSON =
    String -> (Object -> Parser Message) -> Value -> Parser Message
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Message"
      ( \Object
x ->
          Maybe Natural -> ContentType -> Text -> Message
Message'
            (Maybe Natural -> ContentType -> Text -> Message)
-> Parser (Maybe Natural)
-> Parser (ContentType -> Text -> Message)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"groupNumber")
            Parser (ContentType -> Text -> Message)
-> Parser ContentType -> Parser (Text -> Message)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ContentType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"contentType")
            Parser (Text -> Message) -> Parser Text -> Parser Message
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"content")
      )

instance Prelude.Hashable Message

instance Prelude.NFData Message

instance Core.ToJSON Message where
  toJSON :: Message -> Value
toJSON Message' {Maybe Natural
Text
ContentType
content :: Text
contentType :: ContentType
groupNumber :: Maybe Natural
$sel:content:Message' :: Message -> Text
$sel:contentType:Message' :: Message -> ContentType
$sel:groupNumber:Message' :: Message -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"groupNumber" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
groupNumber,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"contentType" Text -> ContentType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ContentType
contentType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"content" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
content)
          ]
      )