{-# 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.DialogState
-- 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.DialogState 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.DialogAction
import Amazonka.LexV2Models.Types.IntentOverride
import qualified Amazonka.Prelude as Prelude

-- | The current state of the conversation with the user.
--
-- /See:/ 'newDialogState' smart constructor.
data DialogState = DialogState'
  { DialogState -> Maybe DialogAction
dialogAction :: Prelude.Maybe DialogAction,
    DialogState -> Maybe IntentOverride
intent :: Prelude.Maybe IntentOverride,
    -- | Map of key\/value pairs representing session-specific context
    -- information. It contains application information passed between Amazon
    -- Lex and a client application.
    DialogState -> Maybe (HashMap Text Text)
sessionAttributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (DialogState -> DialogState -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DialogState -> DialogState -> Bool
$c/= :: DialogState -> DialogState -> Bool
== :: DialogState -> DialogState -> Bool
$c== :: DialogState -> DialogState -> Bool
Prelude.Eq, ReadPrec [DialogState]
ReadPrec DialogState
Int -> ReadS DialogState
ReadS [DialogState]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DialogState]
$creadListPrec :: ReadPrec [DialogState]
readPrec :: ReadPrec DialogState
$creadPrec :: ReadPrec DialogState
readList :: ReadS [DialogState]
$creadList :: ReadS [DialogState]
readsPrec :: Int -> ReadS DialogState
$creadsPrec :: Int -> ReadS DialogState
Prelude.Read, Int -> DialogState -> ShowS
[DialogState] -> ShowS
DialogState -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DialogState] -> ShowS
$cshowList :: [DialogState] -> ShowS
show :: DialogState -> String
$cshow :: DialogState -> String
showsPrec :: Int -> DialogState -> ShowS
$cshowsPrec :: Int -> DialogState -> ShowS
Prelude.Show, forall x. Rep DialogState x -> DialogState
forall x. DialogState -> Rep DialogState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DialogState x -> DialogState
$cfrom :: forall x. DialogState -> Rep DialogState x
Prelude.Generic)

-- |
-- Create a value of 'DialogState' 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:
--
-- 'dialogAction', 'dialogState_dialogAction' - Undocumented member.
--
-- 'intent', 'dialogState_intent' - Undocumented member.
--
-- 'sessionAttributes', 'dialogState_sessionAttributes' - Map of key\/value pairs representing session-specific context
-- information. It contains application information passed between Amazon
-- Lex and a client application.
newDialogState ::
  DialogState
newDialogState :: DialogState
newDialogState =
  DialogState'
    { $sel:dialogAction:DialogState' :: Maybe DialogAction
dialogAction = forall a. Maybe a
Prelude.Nothing,
      $sel:intent:DialogState' :: Maybe IntentOverride
intent = forall a. Maybe a
Prelude.Nothing,
      $sel:sessionAttributes:DialogState' :: Maybe (HashMap Text Text)
sessionAttributes = forall a. Maybe a
Prelude.Nothing
    }

-- | Undocumented member.
dialogState_dialogAction :: Lens.Lens' DialogState (Prelude.Maybe DialogAction)
dialogState_dialogAction :: Lens' DialogState (Maybe DialogAction)
dialogState_dialogAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DialogState' {Maybe DialogAction
dialogAction :: Maybe DialogAction
$sel:dialogAction:DialogState' :: DialogState -> Maybe DialogAction
dialogAction} -> Maybe DialogAction
dialogAction) (\s :: DialogState
s@DialogState' {} Maybe DialogAction
a -> DialogState
s {$sel:dialogAction:DialogState' :: Maybe DialogAction
dialogAction = Maybe DialogAction
a} :: DialogState)

-- | Undocumented member.
dialogState_intent :: Lens.Lens' DialogState (Prelude.Maybe IntentOverride)
dialogState_intent :: Lens' DialogState (Maybe IntentOverride)
dialogState_intent = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DialogState' {Maybe IntentOverride
intent :: Maybe IntentOverride
$sel:intent:DialogState' :: DialogState -> Maybe IntentOverride
intent} -> Maybe IntentOverride
intent) (\s :: DialogState
s@DialogState' {} Maybe IntentOverride
a -> DialogState
s {$sel:intent:DialogState' :: Maybe IntentOverride
intent = Maybe IntentOverride
a} :: DialogState)

-- | Map of key\/value pairs representing session-specific context
-- information. It contains application information passed between Amazon
-- Lex and a client application.
dialogState_sessionAttributes :: Lens.Lens' DialogState (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
dialogState_sessionAttributes :: Lens' DialogState (Maybe (HashMap Text Text))
dialogState_sessionAttributes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DialogState' {Maybe (HashMap Text Text)
sessionAttributes :: Maybe (HashMap Text Text)
$sel:sessionAttributes:DialogState' :: DialogState -> Maybe (HashMap Text Text)
sessionAttributes} -> Maybe (HashMap Text Text)
sessionAttributes) (\s :: DialogState
s@DialogState' {} Maybe (HashMap Text Text)
a -> DialogState
s {$sel:sessionAttributes:DialogState' :: Maybe (HashMap Text Text)
sessionAttributes = Maybe (HashMap Text Text)
a} :: DialogState) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON DialogState where
  parseJSON :: Value -> Parser DialogState
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DialogState"
      ( \Object
x ->
          Maybe DialogAction
-> Maybe IntentOverride -> Maybe (HashMap Text Text) -> DialogState
DialogState'
            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
"dialogAction")
            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
"intent")
            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
"sessionAttributes"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable DialogState where
  hashWithSalt :: Int -> DialogState -> Int
hashWithSalt Int
_salt DialogState' {Maybe (HashMap Text Text)
Maybe DialogAction
Maybe IntentOverride
sessionAttributes :: Maybe (HashMap Text Text)
intent :: Maybe IntentOverride
dialogAction :: Maybe DialogAction
$sel:sessionAttributes:DialogState' :: DialogState -> Maybe (HashMap Text Text)
$sel:intent:DialogState' :: DialogState -> Maybe IntentOverride
$sel:dialogAction:DialogState' :: DialogState -> Maybe DialogAction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DialogAction
dialogAction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe IntentOverride
intent
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
sessionAttributes

instance Prelude.NFData DialogState where
  rnf :: DialogState -> ()
rnf DialogState' {Maybe (HashMap Text Text)
Maybe DialogAction
Maybe IntentOverride
sessionAttributes :: Maybe (HashMap Text Text)
intent :: Maybe IntentOverride
dialogAction :: Maybe DialogAction
$sel:sessionAttributes:DialogState' :: DialogState -> Maybe (HashMap Text Text)
$sel:intent:DialogState' :: DialogState -> Maybe IntentOverride
$sel:dialogAction:DialogState' :: DialogState -> Maybe DialogAction
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe DialogAction
dialogAction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe IntentOverride
intent
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
sessionAttributes

instance Data.ToJSON DialogState where
  toJSON :: DialogState -> Value
toJSON DialogState' {Maybe (HashMap Text Text)
Maybe DialogAction
Maybe IntentOverride
sessionAttributes :: Maybe (HashMap Text Text)
intent :: Maybe IntentOverride
dialogAction :: Maybe DialogAction
$sel:sessionAttributes:DialogState' :: DialogState -> Maybe (HashMap Text Text)
$sel:intent:DialogState' :: DialogState -> Maybe IntentOverride
$sel:dialogAction:DialogState' :: DialogState -> Maybe DialogAction
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"dialogAction" 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 DialogAction
dialogAction,
            (Key
"intent" 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 IntentOverride
intent,
            (Key
"sessionAttributes" 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 (HashMap Text Text)
sessionAttributes
          ]
      )