{-# 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.Statement
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.LexModels.Types.Statement where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LexModels.Types.Message
import qualified Amazonka.Prelude as Prelude

-- | A collection of messages that convey information to the user. At
-- runtime, Amazon Lex selects the message to convey.
--
-- /See:/ 'newStatement' smart constructor.
data Statement = Statement'
  { -- | At runtime, if the client is using the
    -- <http://docs.aws.amazon.com/lex/latest/dg/API_runtime_PostText.html PostText>
    -- API, Amazon Lex includes the response card in the response. It
    -- substitutes all of the session attributes and slot values for
    -- placeholders in the response card.
    Statement -> Maybe Text
responseCard :: Prelude.Maybe Prelude.Text,
    -- | A collection of message objects.
    Statement -> NonEmpty Message
messages :: Prelude.NonEmpty Message
  }
  deriving (Statement -> Statement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Statement -> Statement -> Bool
$c/= :: Statement -> Statement -> Bool
== :: Statement -> Statement -> Bool
$c== :: Statement -> Statement -> Bool
Prelude.Eq, ReadPrec [Statement]
ReadPrec Statement
Int -> ReadS Statement
ReadS [Statement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Statement]
$creadListPrec :: ReadPrec [Statement]
readPrec :: ReadPrec Statement
$creadPrec :: ReadPrec Statement
readList :: ReadS [Statement]
$creadList :: ReadS [Statement]
readsPrec :: Int -> ReadS Statement
$creadsPrec :: Int -> ReadS Statement
Prelude.Read, Int -> Statement -> ShowS
[Statement] -> ShowS
Statement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Statement] -> ShowS
$cshowList :: [Statement] -> ShowS
show :: Statement -> String
$cshow :: Statement -> String
showsPrec :: Int -> Statement -> ShowS
$cshowsPrec :: Int -> Statement -> ShowS
Prelude.Show, forall x. Rep Statement x -> Statement
forall x. Statement -> Rep Statement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Statement x -> Statement
$cfrom :: forall x. Statement -> Rep Statement x
Prelude.Generic)

-- |
-- Create a value of 'Statement' 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:
--
-- 'responseCard', 'statement_responseCard' - At runtime, if the client is using the
-- <http://docs.aws.amazon.com/lex/latest/dg/API_runtime_PostText.html PostText>
-- API, Amazon Lex includes the response card in the response. It
-- substitutes all of the session attributes and slot values for
-- placeholders in the response card.
--
-- 'messages', 'statement_messages' - A collection of message objects.
newStatement ::
  -- | 'messages'
  Prelude.NonEmpty Message ->
  Statement
newStatement :: NonEmpty Message -> Statement
newStatement NonEmpty Message
pMessages_ =
  Statement'
    { $sel:responseCard:Statement' :: Maybe Text
responseCard = forall a. Maybe a
Prelude.Nothing,
      $sel:messages:Statement' :: NonEmpty Message
messages = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Message
pMessages_
    }

-- | At runtime, if the client is using the
-- <http://docs.aws.amazon.com/lex/latest/dg/API_runtime_PostText.html PostText>
-- API, Amazon Lex includes the response card in the response. It
-- substitutes all of the session attributes and slot values for
-- placeholders in the response card.
statement_responseCard :: Lens.Lens' Statement (Prelude.Maybe Prelude.Text)
statement_responseCard :: Lens' Statement (Maybe Text)
statement_responseCard = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Statement' {Maybe Text
responseCard :: Maybe Text
$sel:responseCard:Statement' :: Statement -> Maybe Text
responseCard} -> Maybe Text
responseCard) (\s :: Statement
s@Statement' {} Maybe Text
a -> Statement
s {$sel:responseCard:Statement' :: Maybe Text
responseCard = Maybe Text
a} :: Statement)

-- | A collection of message objects.
statement_messages :: Lens.Lens' Statement (Prelude.NonEmpty Message)
statement_messages :: Lens' Statement (NonEmpty Message)
statement_messages = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Statement' {NonEmpty Message
messages :: NonEmpty Message
$sel:messages:Statement' :: Statement -> NonEmpty Message
messages} -> NonEmpty Message
messages) (\s :: Statement
s@Statement' {} NonEmpty Message
a -> Statement
s {$sel:messages:Statement' :: NonEmpty Message
messages = NonEmpty Message
a} :: Statement) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON Statement where
  parseJSON :: Value -> Parser Statement
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Statement"
      ( \Object
x ->
          Maybe Text -> NonEmpty Message -> Statement
Statement'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"responseCard")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"messages")
      )

instance Prelude.Hashable Statement where
  hashWithSalt :: Int -> Statement -> Int
hashWithSalt Int
_salt Statement' {Maybe Text
NonEmpty Message
messages :: NonEmpty Message
responseCard :: Maybe Text
$sel:messages:Statement' :: Statement -> NonEmpty Message
$sel:responseCard:Statement' :: Statement -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
responseCard
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Message
messages

instance Prelude.NFData Statement where
  rnf :: Statement -> ()
rnf Statement' {Maybe Text
NonEmpty Message
messages :: NonEmpty Message
responseCard :: Maybe Text
$sel:messages:Statement' :: Statement -> NonEmpty Message
$sel:responseCard:Statement' :: Statement -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
responseCard
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Message
messages

instance Data.ToJSON Statement where
  toJSON :: Statement -> Value
toJSON Statement' {Maybe Text
NonEmpty Message
messages :: NonEmpty Message
responseCard :: Maybe Text
$sel:messages:Statement' :: Statement -> NonEmpty Message
$sel:responseCard:Statement' :: Statement -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"responseCard" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
responseCard,
            forall a. a -> Maybe a
Prelude.Just (Key
"messages" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Message
messages)
          ]
      )