{-# 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.LexV2Models.Types.DialogAction
-- 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.LexV2Models.Types.DialogAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LexV2Models.Types.DialogActionType
import qualified Amazonka.Prelude as Prelude

-- | Defines the action that the bot executes at runtime when the
-- conversation reaches this step.
--
-- /See:/ 'newDialogAction' smart constructor.
data DialogAction = DialogAction'
  { -- | If the dialog action is @ElicitSlot@, defines the slot to elicit from
    -- the user.
    DialogAction -> Maybe Text
slotToElicit :: Prelude.Maybe Prelude.Text,
    -- | When true the next message for the intent is not used.
    DialogAction -> Maybe Bool
suppressNextMessage :: Prelude.Maybe Prelude.Bool,
    -- | The action that the bot should execute.
    DialogAction -> DialogActionType
type' :: DialogActionType
  }
  deriving (DialogAction -> DialogAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DialogAction -> DialogAction -> Bool
$c/= :: DialogAction -> DialogAction -> Bool
== :: DialogAction -> DialogAction -> Bool
$c== :: DialogAction -> DialogAction -> Bool
Prelude.Eq, ReadPrec [DialogAction]
ReadPrec DialogAction
Int -> ReadS DialogAction
ReadS [DialogAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DialogAction]
$creadListPrec :: ReadPrec [DialogAction]
readPrec :: ReadPrec DialogAction
$creadPrec :: ReadPrec DialogAction
readList :: ReadS [DialogAction]
$creadList :: ReadS [DialogAction]
readsPrec :: Int -> ReadS DialogAction
$creadsPrec :: Int -> ReadS DialogAction
Prelude.Read, Int -> DialogAction -> ShowS
[DialogAction] -> ShowS
DialogAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DialogAction] -> ShowS
$cshowList :: [DialogAction] -> ShowS
show :: DialogAction -> String
$cshow :: DialogAction -> String
showsPrec :: Int -> DialogAction -> ShowS
$cshowsPrec :: Int -> DialogAction -> ShowS
Prelude.Show, forall x. Rep DialogAction x -> DialogAction
forall x. DialogAction -> Rep DialogAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DialogAction x -> DialogAction
$cfrom :: forall x. DialogAction -> Rep DialogAction x
Prelude.Generic)

-- |
-- Create a value of 'DialogAction' 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:
--
-- 'slotToElicit', 'dialogAction_slotToElicit' - If the dialog action is @ElicitSlot@, defines the slot to elicit from
-- the user.
--
-- 'suppressNextMessage', 'dialogAction_suppressNextMessage' - When true the next message for the intent is not used.
--
-- 'type'', 'dialogAction_type' - The action that the bot should execute.
newDialogAction ::
  -- | 'type''
  DialogActionType ->
  DialogAction
newDialogAction :: DialogActionType -> DialogAction
newDialogAction DialogActionType
pType_ =
  DialogAction'
    { $sel:slotToElicit:DialogAction' :: Maybe Text
slotToElicit = forall a. Maybe a
Prelude.Nothing,
      $sel:suppressNextMessage:DialogAction' :: Maybe Bool
suppressNextMessage = forall a. Maybe a
Prelude.Nothing,
      $sel:type':DialogAction' :: DialogActionType
type' = DialogActionType
pType_
    }

-- | If the dialog action is @ElicitSlot@, defines the slot to elicit from
-- the user.
dialogAction_slotToElicit :: Lens.Lens' DialogAction (Prelude.Maybe Prelude.Text)
dialogAction_slotToElicit :: Lens' DialogAction (Maybe Text)
dialogAction_slotToElicit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DialogAction' {Maybe Text
slotToElicit :: Maybe Text
$sel:slotToElicit:DialogAction' :: DialogAction -> Maybe Text
slotToElicit} -> Maybe Text
slotToElicit) (\s :: DialogAction
s@DialogAction' {} Maybe Text
a -> DialogAction
s {$sel:slotToElicit:DialogAction' :: Maybe Text
slotToElicit = Maybe Text
a} :: DialogAction)

-- | When true the next message for the intent is not used.
dialogAction_suppressNextMessage :: Lens.Lens' DialogAction (Prelude.Maybe Prelude.Bool)
dialogAction_suppressNextMessage :: Lens' DialogAction (Maybe Bool)
dialogAction_suppressNextMessage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DialogAction' {Maybe Bool
suppressNextMessage :: Maybe Bool
$sel:suppressNextMessage:DialogAction' :: DialogAction -> Maybe Bool
suppressNextMessage} -> Maybe Bool
suppressNextMessage) (\s :: DialogAction
s@DialogAction' {} Maybe Bool
a -> DialogAction
s {$sel:suppressNextMessage:DialogAction' :: Maybe Bool
suppressNextMessage = Maybe Bool
a} :: DialogAction)

-- | The action that the bot should execute.
dialogAction_type :: Lens.Lens' DialogAction DialogActionType
dialogAction_type :: Lens' DialogAction DialogActionType
dialogAction_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DialogAction' {DialogActionType
type' :: DialogActionType
$sel:type':DialogAction' :: DialogAction -> DialogActionType
type'} -> DialogActionType
type') (\s :: DialogAction
s@DialogAction' {} DialogActionType
a -> DialogAction
s {$sel:type':DialogAction' :: DialogActionType
type' = DialogActionType
a} :: DialogAction)

instance Data.FromJSON DialogAction where
  parseJSON :: Value -> Parser DialogAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DialogAction"
      ( \Object
x ->
          Maybe Text -> Maybe Bool -> DialogActionType -> DialogAction
DialogAction'
            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
"slotToElicit")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"suppressNextMessage")
            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
"type")
      )

instance Prelude.Hashable DialogAction where
  hashWithSalt :: Int -> DialogAction -> Int
hashWithSalt Int
_salt DialogAction' {Maybe Bool
Maybe Text
DialogActionType
type' :: DialogActionType
suppressNextMessage :: Maybe Bool
slotToElicit :: Maybe Text
$sel:type':DialogAction' :: DialogAction -> DialogActionType
$sel:suppressNextMessage:DialogAction' :: DialogAction -> Maybe Bool
$sel:slotToElicit:DialogAction' :: DialogAction -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
slotToElicit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
suppressNextMessage
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DialogActionType
type'

instance Prelude.NFData DialogAction where
  rnf :: DialogAction -> ()
rnf DialogAction' {Maybe Bool
Maybe Text
DialogActionType
type' :: DialogActionType
suppressNextMessage :: Maybe Bool
slotToElicit :: Maybe Text
$sel:type':DialogAction' :: DialogAction -> DialogActionType
$sel:suppressNextMessage:DialogAction' :: DialogAction -> Maybe Bool
$sel:slotToElicit:DialogAction' :: DialogAction -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
slotToElicit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
suppressNextMessage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DialogActionType
type'

instance Data.ToJSON DialogAction where
  toJSON :: DialogAction -> Value
toJSON DialogAction' {Maybe Bool
Maybe Text
DialogActionType
type' :: DialogActionType
suppressNextMessage :: Maybe Bool
slotToElicit :: Maybe Text
$sel:type':DialogAction' :: DialogAction -> DialogActionType
$sel:suppressNextMessage:DialogAction' :: DialogAction -> Maybe Bool
$sel:slotToElicit:DialogAction' :: DialogAction -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"slotToElicit" 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
slotToElicit,
            (Key
"suppressNextMessage" 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 Bool
suppressNextMessage,
            forall a. a -> Maybe a
Prelude.Just (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DialogActionType
type')
          ]
      )