{-# 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-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.Statement where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(Statement -> Statement -> Bool)
-> (Statement -> Statement -> Bool) -> Eq Statement
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]
(Int -> ReadS Statement)
-> ReadS [Statement]
-> ReadPrec Statement
-> ReadPrec [Statement]
-> Read 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
(Int -> Statement -> ShowS)
-> (Statement -> String)
-> ([Statement] -> ShowS)
-> Show Statement
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. Statement -> Rep Statement x)
-> (forall x. Rep Statement x -> Statement) -> Generic Statement
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' :: Maybe Text -> NonEmpty Message -> Statement
Statement'
    { $sel:responseCard:Statement' :: Maybe Text
responseCard = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:messages:Statement' :: NonEmpty Message
messages = Tagged (NonEmpty Message) (Identity (NonEmpty Message))
-> Tagged (NonEmpty Message) (Identity (NonEmpty Message))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Message) (Identity (NonEmpty Message))
 -> Tagged (NonEmpty Message) (Identity (NonEmpty Message)))
-> NonEmpty Message -> NonEmpty Message
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 :: (Maybe Text -> f (Maybe Text)) -> Statement -> f Statement
statement_responseCard = (Statement -> Maybe Text)
-> (Statement -> Maybe Text -> Statement)
-> Lens Statement Statement (Maybe Text) (Maybe Text)
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 :: (NonEmpty Message -> f (NonEmpty Message))
-> Statement -> f Statement
statement_messages = (Statement -> NonEmpty Message)
-> (Statement -> NonEmpty Message -> Statement)
-> Lens Statement Statement (NonEmpty Message) (NonEmpty Message)
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) ((NonEmpty Message -> f (NonEmpty Message))
 -> Statement -> f Statement)
-> ((NonEmpty Message -> f (NonEmpty Message))
    -> NonEmpty Message -> f (NonEmpty Message))
-> (NonEmpty Message -> f (NonEmpty Message))
-> Statement
-> f Statement
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Message -> f (NonEmpty Message))
-> NonEmpty Message -> f (NonEmpty Message)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable Statement

instance Prelude.NFData Statement

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"responseCard" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
responseCard,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"messages" Text -> NonEmpty Message -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Message
messages)
          ]
      )