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

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

-- | Obtains information from the user. To define a prompt, provide one or
-- more messages and specify the number of attempts to get information from
-- the user. If you provide more than one message, Amazon Lex chooses one
-- of the messages to use to prompt the user. For more information, see
-- how-it-works.
--
-- /See:/ 'newPrompt' smart constructor.
data Prompt = Prompt'
  { -- | A response card. Amazon Lex uses this prompt at runtime, in the
    -- @PostText@ API response. It substitutes session attributes and slot
    -- values for placeholders in the response card. For more information, see
    -- ex-resp-card.
    Prompt -> Maybe Text
responseCard :: Prelude.Maybe Prelude.Text,
    -- | An array of objects, each of which provides a message string and its
    -- type. You can specify the message string in plain text or in Speech
    -- Synthesis Markup Language (SSML).
    Prompt -> NonEmpty Message
messages :: Prelude.NonEmpty Message,
    -- | The number of times to prompt the user for information.
    Prompt -> Natural
maxAttempts :: Prelude.Natural
  }
  deriving (Prompt -> Prompt -> Bool
(Prompt -> Prompt -> Bool)
-> (Prompt -> Prompt -> Bool) -> Eq Prompt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Prompt -> Prompt -> Bool
$c/= :: Prompt -> Prompt -> Bool
== :: Prompt -> Prompt -> Bool
$c== :: Prompt -> Prompt -> Bool
Prelude.Eq, ReadPrec [Prompt]
ReadPrec Prompt
Int -> ReadS Prompt
ReadS [Prompt]
(Int -> ReadS Prompt)
-> ReadS [Prompt]
-> ReadPrec Prompt
-> ReadPrec [Prompt]
-> Read Prompt
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Prompt]
$creadListPrec :: ReadPrec [Prompt]
readPrec :: ReadPrec Prompt
$creadPrec :: ReadPrec Prompt
readList :: ReadS [Prompt]
$creadList :: ReadS [Prompt]
readsPrec :: Int -> ReadS Prompt
$creadsPrec :: Int -> ReadS Prompt
Prelude.Read, Int -> Prompt -> ShowS
[Prompt] -> ShowS
Prompt -> String
(Int -> Prompt -> ShowS)
-> (Prompt -> String) -> ([Prompt] -> ShowS) -> Show Prompt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Prompt] -> ShowS
$cshowList :: [Prompt] -> ShowS
show :: Prompt -> String
$cshow :: Prompt -> String
showsPrec :: Int -> Prompt -> ShowS
$cshowsPrec :: Int -> Prompt -> ShowS
Prelude.Show, (forall x. Prompt -> Rep Prompt x)
-> (forall x. Rep Prompt x -> Prompt) -> Generic Prompt
forall x. Rep Prompt x -> Prompt
forall x. Prompt -> Rep Prompt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Prompt x -> Prompt
$cfrom :: forall x. Prompt -> Rep Prompt x
Prelude.Generic)

-- |
-- Create a value of 'Prompt' 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', 'prompt_responseCard' - A response card. Amazon Lex uses this prompt at runtime, in the
-- @PostText@ API response. It substitutes session attributes and slot
-- values for placeholders in the response card. For more information, see
-- ex-resp-card.
--
-- 'messages', 'prompt_messages' - An array of objects, each of which provides a message string and its
-- type. You can specify the message string in plain text or in Speech
-- Synthesis Markup Language (SSML).
--
-- 'maxAttempts', 'prompt_maxAttempts' - The number of times to prompt the user for information.
newPrompt ::
  -- | 'messages'
  Prelude.NonEmpty Message ->
  -- | 'maxAttempts'
  Prelude.Natural ->
  Prompt
newPrompt :: NonEmpty Message -> Natural -> Prompt
newPrompt NonEmpty Message
pMessages_ Natural
pMaxAttempts_ =
  Prompt' :: Maybe Text -> NonEmpty Message -> Natural -> Prompt
Prompt'
    { $sel:responseCard:Prompt' :: Maybe Text
responseCard = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:messages:Prompt' :: 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_,
      $sel:maxAttempts:Prompt' :: Natural
maxAttempts = Natural
pMaxAttempts_
    }

-- | A response card. Amazon Lex uses this prompt at runtime, in the
-- @PostText@ API response. It substitutes session attributes and slot
-- values for placeholders in the response card. For more information, see
-- ex-resp-card.
prompt_responseCard :: Lens.Lens' Prompt (Prelude.Maybe Prelude.Text)
prompt_responseCard :: (Maybe Text -> f (Maybe Text)) -> Prompt -> f Prompt
prompt_responseCard = (Prompt -> Maybe Text)
-> (Prompt -> Maybe Text -> Prompt)
-> Lens Prompt Prompt (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Prompt' {Maybe Text
responseCard :: Maybe Text
$sel:responseCard:Prompt' :: Prompt -> Maybe Text
responseCard} -> Maybe Text
responseCard) (\s :: Prompt
s@Prompt' {} Maybe Text
a -> Prompt
s {$sel:responseCard:Prompt' :: Maybe Text
responseCard = Maybe Text
a} :: Prompt)

-- | An array of objects, each of which provides a message string and its
-- type. You can specify the message string in plain text or in Speech
-- Synthesis Markup Language (SSML).
prompt_messages :: Lens.Lens' Prompt (Prelude.NonEmpty Message)
prompt_messages :: (NonEmpty Message -> f (NonEmpty Message)) -> Prompt -> f Prompt
prompt_messages = (Prompt -> NonEmpty Message)
-> (Prompt -> NonEmpty Message -> Prompt)
-> Lens Prompt Prompt (NonEmpty Message) (NonEmpty Message)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Prompt' {NonEmpty Message
messages :: NonEmpty Message
$sel:messages:Prompt' :: Prompt -> NonEmpty Message
messages} -> NonEmpty Message
messages) (\s :: Prompt
s@Prompt' {} NonEmpty Message
a -> Prompt
s {$sel:messages:Prompt' :: NonEmpty Message
messages = NonEmpty Message
a} :: Prompt) ((NonEmpty Message -> f (NonEmpty Message)) -> Prompt -> f Prompt)
-> ((NonEmpty Message -> f (NonEmpty Message))
    -> NonEmpty Message -> f (NonEmpty Message))
-> (NonEmpty Message -> f (NonEmpty Message))
-> Prompt
-> f Prompt
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

-- | The number of times to prompt the user for information.
prompt_maxAttempts :: Lens.Lens' Prompt Prelude.Natural
prompt_maxAttempts :: (Natural -> f Natural) -> Prompt -> f Prompt
prompt_maxAttempts = (Prompt -> Natural)
-> (Prompt -> Natural -> Prompt)
-> Lens Prompt Prompt Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Prompt' {Natural
maxAttempts :: Natural
$sel:maxAttempts:Prompt' :: Prompt -> Natural
maxAttempts} -> Natural
maxAttempts) (\s :: Prompt
s@Prompt' {} Natural
a -> Prompt
s {$sel:maxAttempts:Prompt' :: Natural
maxAttempts = Natural
a} :: Prompt)

instance Core.FromJSON Prompt where
  parseJSON :: Value -> Parser Prompt
parseJSON =
    String -> (Object -> Parser Prompt) -> Value -> Parser Prompt
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Prompt"
      ( \Object
x ->
          Maybe Text -> NonEmpty Message -> Natural -> Prompt
Prompt'
            (Maybe Text -> NonEmpty Message -> Natural -> Prompt)
-> Parser (Maybe Text)
-> Parser (NonEmpty Message -> Natural -> Prompt)
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 -> Natural -> Prompt)
-> Parser (NonEmpty Message) -> Parser (Natural -> Prompt)
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")
            Parser (Natural -> Prompt) -> Parser Natural -> Parser Prompt
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"maxAttempts")
      )

instance Prelude.Hashable Prompt

instance Prelude.NFData Prompt

instance Core.ToJSON Prompt where
  toJSON :: Prompt -> Value
toJSON Prompt' {Natural
Maybe Text
NonEmpty Message
maxAttempts :: Natural
messages :: NonEmpty Message
responseCard :: Maybe Text
$sel:maxAttempts:Prompt' :: Prompt -> Natural
$sel:messages:Prompt' :: Prompt -> NonEmpty Message
$sel:responseCard:Prompt' :: Prompt -> 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),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"maxAttempts" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
maxAttempts)
          ]
      )