{-# 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.FulfillmentActivity
-- 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.FulfillmentActivity 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.CodeHook
import Amazonka.LexModels.Types.FulfillmentActivityType
import qualified Amazonka.Prelude as Prelude

-- | Describes how the intent is fulfilled after the user provides all of the
-- information required for the intent. You can provide a Lambda function
-- to process the intent, or you can return the intent information to the
-- client application. We recommend that you use a Lambda function so that
-- the relevant logic lives in the Cloud and limit the client-side code
-- primarily to presentation. If you need to update the logic, you only
-- update the Lambda function; you don\'t need to upgrade your client
-- application.
--
-- Consider the following examples:
--
-- -   In a pizza ordering application, after the user provides all of the
--     information for placing an order, you use a Lambda function to place
--     an order with a pizzeria.
--
-- -   In a gaming application, when a user says \"pick up a rock,\" this
--     information must go back to the client application so that it can
--     perform the operation and update the graphics. In this case, you
--     want Amazon Lex to return the intent data to the client.
--
-- /See:/ 'newFulfillmentActivity' smart constructor.
data FulfillmentActivity = FulfillmentActivity'
  { -- | A description of the Lambda function that is run to fulfill the intent.
    FulfillmentActivity -> Maybe CodeHook
codeHook :: Prelude.Maybe CodeHook,
    -- | How the intent should be fulfilled, either by running a Lambda function
    -- or by returning the slot data to the client application.
    FulfillmentActivity -> FulfillmentActivityType
type' :: FulfillmentActivityType
  }
  deriving (FulfillmentActivity -> FulfillmentActivity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FulfillmentActivity -> FulfillmentActivity -> Bool
$c/= :: FulfillmentActivity -> FulfillmentActivity -> Bool
== :: FulfillmentActivity -> FulfillmentActivity -> Bool
$c== :: FulfillmentActivity -> FulfillmentActivity -> Bool
Prelude.Eq, ReadPrec [FulfillmentActivity]
ReadPrec FulfillmentActivity
Int -> ReadS FulfillmentActivity
ReadS [FulfillmentActivity]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FulfillmentActivity]
$creadListPrec :: ReadPrec [FulfillmentActivity]
readPrec :: ReadPrec FulfillmentActivity
$creadPrec :: ReadPrec FulfillmentActivity
readList :: ReadS [FulfillmentActivity]
$creadList :: ReadS [FulfillmentActivity]
readsPrec :: Int -> ReadS FulfillmentActivity
$creadsPrec :: Int -> ReadS FulfillmentActivity
Prelude.Read, Int -> FulfillmentActivity -> ShowS
[FulfillmentActivity] -> ShowS
FulfillmentActivity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FulfillmentActivity] -> ShowS
$cshowList :: [FulfillmentActivity] -> ShowS
show :: FulfillmentActivity -> String
$cshow :: FulfillmentActivity -> String
showsPrec :: Int -> FulfillmentActivity -> ShowS
$cshowsPrec :: Int -> FulfillmentActivity -> ShowS
Prelude.Show, forall x. Rep FulfillmentActivity x -> FulfillmentActivity
forall x. FulfillmentActivity -> Rep FulfillmentActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FulfillmentActivity x -> FulfillmentActivity
$cfrom :: forall x. FulfillmentActivity -> Rep FulfillmentActivity x
Prelude.Generic)

-- |
-- Create a value of 'FulfillmentActivity' 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:
--
-- 'codeHook', 'fulfillmentActivity_codeHook' - A description of the Lambda function that is run to fulfill the intent.
--
-- 'type'', 'fulfillmentActivity_type' - How the intent should be fulfilled, either by running a Lambda function
-- or by returning the slot data to the client application.
newFulfillmentActivity ::
  -- | 'type''
  FulfillmentActivityType ->
  FulfillmentActivity
newFulfillmentActivity :: FulfillmentActivityType -> FulfillmentActivity
newFulfillmentActivity FulfillmentActivityType
pType_ =
  FulfillmentActivity'
    { $sel:codeHook:FulfillmentActivity' :: Maybe CodeHook
codeHook = forall a. Maybe a
Prelude.Nothing,
      $sel:type':FulfillmentActivity' :: FulfillmentActivityType
type' = FulfillmentActivityType
pType_
    }

-- | A description of the Lambda function that is run to fulfill the intent.
fulfillmentActivity_codeHook :: Lens.Lens' FulfillmentActivity (Prelude.Maybe CodeHook)
fulfillmentActivity_codeHook :: Lens' FulfillmentActivity (Maybe CodeHook)
fulfillmentActivity_codeHook = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FulfillmentActivity' {Maybe CodeHook
codeHook :: Maybe CodeHook
$sel:codeHook:FulfillmentActivity' :: FulfillmentActivity -> Maybe CodeHook
codeHook} -> Maybe CodeHook
codeHook) (\s :: FulfillmentActivity
s@FulfillmentActivity' {} Maybe CodeHook
a -> FulfillmentActivity
s {$sel:codeHook:FulfillmentActivity' :: Maybe CodeHook
codeHook = Maybe CodeHook
a} :: FulfillmentActivity)

-- | How the intent should be fulfilled, either by running a Lambda function
-- or by returning the slot data to the client application.
fulfillmentActivity_type :: Lens.Lens' FulfillmentActivity FulfillmentActivityType
fulfillmentActivity_type :: Lens' FulfillmentActivity FulfillmentActivityType
fulfillmentActivity_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FulfillmentActivity' {FulfillmentActivityType
type' :: FulfillmentActivityType
$sel:type':FulfillmentActivity' :: FulfillmentActivity -> FulfillmentActivityType
type'} -> FulfillmentActivityType
type') (\s :: FulfillmentActivity
s@FulfillmentActivity' {} FulfillmentActivityType
a -> FulfillmentActivity
s {$sel:type':FulfillmentActivity' :: FulfillmentActivityType
type' = FulfillmentActivityType
a} :: FulfillmentActivity)

instance Data.FromJSON FulfillmentActivity where
  parseJSON :: Value -> Parser FulfillmentActivity
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FulfillmentActivity"
      ( \Object
x ->
          Maybe CodeHook -> FulfillmentActivityType -> FulfillmentActivity
FulfillmentActivity'
            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
"codeHook")
            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 FulfillmentActivity where
  hashWithSalt :: Int -> FulfillmentActivity -> Int
hashWithSalt Int
_salt FulfillmentActivity' {Maybe CodeHook
FulfillmentActivityType
type' :: FulfillmentActivityType
codeHook :: Maybe CodeHook
$sel:type':FulfillmentActivity' :: FulfillmentActivity -> FulfillmentActivityType
$sel:codeHook:FulfillmentActivity' :: FulfillmentActivity -> Maybe CodeHook
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CodeHook
codeHook
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FulfillmentActivityType
type'

instance Prelude.NFData FulfillmentActivity where
  rnf :: FulfillmentActivity -> ()
rnf FulfillmentActivity' {Maybe CodeHook
FulfillmentActivityType
type' :: FulfillmentActivityType
codeHook :: Maybe CodeHook
$sel:type':FulfillmentActivity' :: FulfillmentActivity -> FulfillmentActivityType
$sel:codeHook:FulfillmentActivity' :: FulfillmentActivity -> Maybe CodeHook
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CodeHook
codeHook
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf FulfillmentActivityType
type'

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