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

-- | 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
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]
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
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. 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'
    { $sel:responseCard:Prompt' :: Maybe Text
responseCard = forall a. Maybe a
Prelude.Nothing,
      $sel:messages:Prompt' :: 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_,
      $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 :: Lens' Prompt (Maybe Text)
prompt_responseCard = 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 :: Lens' Prompt (NonEmpty Message)
prompt_messages = 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) 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

-- | The number of times to prompt the user for information.
prompt_maxAttempts :: Lens.Lens' Prompt Prelude.Natural
prompt_maxAttempts :: Lens' Prompt Natural
prompt_maxAttempts = 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 Data.FromJSON Prompt where
  parseJSON :: Value -> Parser Prompt
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Prompt"
      ( \Object
x ->
          Maybe Text -> NonEmpty Message -> Natural -> Prompt
Prompt'
            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")
            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
"maxAttempts")
      )

instance Prelude.Hashable Prompt where
  hashWithSalt :: Int -> Prompt -> Int
hashWithSalt Int
_salt 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
..} =
    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
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
maxAttempts

instance Prelude.NFData Prompt where
  rnf :: Prompt -> ()
rnf 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
..} =
    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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
maxAttempts

instance Data.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
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),
            forall a. a -> Maybe a
Prelude.Just (Key
"maxAttempts" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
maxAttempts)
          ]
      )