{-# 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.ConditionalBranch
-- 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.ConditionalBranch 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.Condition
import Amazonka.LexV2Models.Types.DialogState
import Amazonka.LexV2Models.Types.ResponseSpecification
import qualified Amazonka.Prelude as Prelude

-- | A set of actions that Amazon Lex should run if the condition is matched.
--
-- /See:/ 'newConditionalBranch' smart constructor.
data ConditionalBranch = ConditionalBranch'
  { ConditionalBranch -> Maybe ResponseSpecification
response :: Prelude.Maybe ResponseSpecification,
    -- | The name of the branch.
    ConditionalBranch -> Text
name :: Prelude.Text,
    -- | Contains the expression to evaluate. If the condition is true, the
    -- branch\'s actions are taken.
    ConditionalBranch -> Condition
condition :: Condition,
    -- | The next step in the conversation.
    ConditionalBranch -> DialogState
nextStep :: DialogState
  }
  deriving (ConditionalBranch -> ConditionalBranch -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConditionalBranch -> ConditionalBranch -> Bool
$c/= :: ConditionalBranch -> ConditionalBranch -> Bool
== :: ConditionalBranch -> ConditionalBranch -> Bool
$c== :: ConditionalBranch -> ConditionalBranch -> Bool
Prelude.Eq, ReadPrec [ConditionalBranch]
ReadPrec ConditionalBranch
Int -> ReadS ConditionalBranch
ReadS [ConditionalBranch]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConditionalBranch]
$creadListPrec :: ReadPrec [ConditionalBranch]
readPrec :: ReadPrec ConditionalBranch
$creadPrec :: ReadPrec ConditionalBranch
readList :: ReadS [ConditionalBranch]
$creadList :: ReadS [ConditionalBranch]
readsPrec :: Int -> ReadS ConditionalBranch
$creadsPrec :: Int -> ReadS ConditionalBranch
Prelude.Read, Int -> ConditionalBranch -> ShowS
[ConditionalBranch] -> ShowS
ConditionalBranch -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConditionalBranch] -> ShowS
$cshowList :: [ConditionalBranch] -> ShowS
show :: ConditionalBranch -> String
$cshow :: ConditionalBranch -> String
showsPrec :: Int -> ConditionalBranch -> ShowS
$cshowsPrec :: Int -> ConditionalBranch -> ShowS
Prelude.Show, forall x. Rep ConditionalBranch x -> ConditionalBranch
forall x. ConditionalBranch -> Rep ConditionalBranch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConditionalBranch x -> ConditionalBranch
$cfrom :: forall x. ConditionalBranch -> Rep ConditionalBranch x
Prelude.Generic)

-- |
-- Create a value of 'ConditionalBranch' 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:
--
-- 'response', 'conditionalBranch_response' - Undocumented member.
--
-- 'name', 'conditionalBranch_name' - The name of the branch.
--
-- 'condition', 'conditionalBranch_condition' - Contains the expression to evaluate. If the condition is true, the
-- branch\'s actions are taken.
--
-- 'nextStep', 'conditionalBranch_nextStep' - The next step in the conversation.
newConditionalBranch ::
  -- | 'name'
  Prelude.Text ->
  -- | 'condition'
  Condition ->
  -- | 'nextStep'
  DialogState ->
  ConditionalBranch
newConditionalBranch :: Text -> Condition -> DialogState -> ConditionalBranch
newConditionalBranch Text
pName_ Condition
pCondition_ DialogState
pNextStep_ =
  ConditionalBranch'
    { $sel:response:ConditionalBranch' :: Maybe ResponseSpecification
response = forall a. Maybe a
Prelude.Nothing,
      $sel:name:ConditionalBranch' :: Text
name = Text
pName_,
      $sel:condition:ConditionalBranch' :: Condition
condition = Condition
pCondition_,
      $sel:nextStep:ConditionalBranch' :: DialogState
nextStep = DialogState
pNextStep_
    }

-- | Undocumented member.
conditionalBranch_response :: Lens.Lens' ConditionalBranch (Prelude.Maybe ResponseSpecification)
conditionalBranch_response :: Lens' ConditionalBranch (Maybe ResponseSpecification)
conditionalBranch_response = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionalBranch' {Maybe ResponseSpecification
response :: Maybe ResponseSpecification
$sel:response:ConditionalBranch' :: ConditionalBranch -> Maybe ResponseSpecification
response} -> Maybe ResponseSpecification
response) (\s :: ConditionalBranch
s@ConditionalBranch' {} Maybe ResponseSpecification
a -> ConditionalBranch
s {$sel:response:ConditionalBranch' :: Maybe ResponseSpecification
response = Maybe ResponseSpecification
a} :: ConditionalBranch)

-- | The name of the branch.
conditionalBranch_name :: Lens.Lens' ConditionalBranch Prelude.Text
conditionalBranch_name :: Lens' ConditionalBranch Text
conditionalBranch_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionalBranch' {Text
name :: Text
$sel:name:ConditionalBranch' :: ConditionalBranch -> Text
name} -> Text
name) (\s :: ConditionalBranch
s@ConditionalBranch' {} Text
a -> ConditionalBranch
s {$sel:name:ConditionalBranch' :: Text
name = Text
a} :: ConditionalBranch)

-- | Contains the expression to evaluate. If the condition is true, the
-- branch\'s actions are taken.
conditionalBranch_condition :: Lens.Lens' ConditionalBranch Condition
conditionalBranch_condition :: Lens' ConditionalBranch Condition
conditionalBranch_condition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionalBranch' {Condition
condition :: Condition
$sel:condition:ConditionalBranch' :: ConditionalBranch -> Condition
condition} -> Condition
condition) (\s :: ConditionalBranch
s@ConditionalBranch' {} Condition
a -> ConditionalBranch
s {$sel:condition:ConditionalBranch' :: Condition
condition = Condition
a} :: ConditionalBranch)

-- | The next step in the conversation.
conditionalBranch_nextStep :: Lens.Lens' ConditionalBranch DialogState
conditionalBranch_nextStep :: Lens' ConditionalBranch DialogState
conditionalBranch_nextStep = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionalBranch' {DialogState
nextStep :: DialogState
$sel:nextStep:ConditionalBranch' :: ConditionalBranch -> DialogState
nextStep} -> DialogState
nextStep) (\s :: ConditionalBranch
s@ConditionalBranch' {} DialogState
a -> ConditionalBranch
s {$sel:nextStep:ConditionalBranch' :: DialogState
nextStep = DialogState
a} :: ConditionalBranch)

instance Data.FromJSON ConditionalBranch where
  parseJSON :: Value -> Parser ConditionalBranch
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ConditionalBranch"
      ( \Object
x ->
          Maybe ResponseSpecification
-> Text -> Condition -> DialogState -> ConditionalBranch
ConditionalBranch'
            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
"response")
            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
"name")
            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
"condition")
            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
"nextStep")
      )

instance Prelude.Hashable ConditionalBranch where
  hashWithSalt :: Int -> ConditionalBranch -> Int
hashWithSalt Int
_salt ConditionalBranch' {Maybe ResponseSpecification
Text
Condition
DialogState
nextStep :: DialogState
condition :: Condition
name :: Text
response :: Maybe ResponseSpecification
$sel:nextStep:ConditionalBranch' :: ConditionalBranch -> DialogState
$sel:condition:ConditionalBranch' :: ConditionalBranch -> Condition
$sel:name:ConditionalBranch' :: ConditionalBranch -> Text
$sel:response:ConditionalBranch' :: ConditionalBranch -> Maybe ResponseSpecification
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ResponseSpecification
response
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Condition
condition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DialogState
nextStep

instance Prelude.NFData ConditionalBranch where
  rnf :: ConditionalBranch -> ()
rnf ConditionalBranch' {Maybe ResponseSpecification
Text
Condition
DialogState
nextStep :: DialogState
condition :: Condition
name :: Text
response :: Maybe ResponseSpecification
$sel:nextStep:ConditionalBranch' :: ConditionalBranch -> DialogState
$sel:condition:ConditionalBranch' :: ConditionalBranch -> Condition
$sel:name:ConditionalBranch' :: ConditionalBranch -> Text
$sel:response:ConditionalBranch' :: ConditionalBranch -> Maybe ResponseSpecification
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ResponseSpecification
response
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Condition
condition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DialogState
nextStep

instance Data.ToJSON ConditionalBranch where
  toJSON :: ConditionalBranch -> Value
toJSON ConditionalBranch' {Maybe ResponseSpecification
Text
Condition
DialogState
nextStep :: DialogState
condition :: Condition
name :: Text
response :: Maybe ResponseSpecification
$sel:nextStep:ConditionalBranch' :: ConditionalBranch -> DialogState
$sel:condition:ConditionalBranch' :: ConditionalBranch -> Condition
$sel:name:ConditionalBranch' :: ConditionalBranch -> Text
$sel:response:ConditionalBranch' :: ConditionalBranch -> Maybe ResponseSpecification
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"response" 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 ResponseSpecification
response,
            forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"condition" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Condition
condition),
            forall a. a -> Maybe a
Prelude.Just (Key
"nextStep" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DialogState
nextStep)
          ]
      )