{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.LexModels.Types.FulfillmentActivity where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(FulfillmentActivity -> FulfillmentActivity -> Bool)
-> (FulfillmentActivity -> FulfillmentActivity -> Bool)
-> Eq FulfillmentActivity
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]
(Int -> ReadS FulfillmentActivity)
-> ReadS [FulfillmentActivity]
-> ReadPrec FulfillmentActivity
-> ReadPrec [FulfillmentActivity]
-> Read 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
(Int -> FulfillmentActivity -> ShowS)
-> (FulfillmentActivity -> String)
-> ([FulfillmentActivity] -> ShowS)
-> Show FulfillmentActivity
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. FulfillmentActivity -> Rep FulfillmentActivity x)
-> (forall x. Rep FulfillmentActivity x -> FulfillmentActivity)
-> Generic FulfillmentActivity
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' :: Maybe CodeHook -> FulfillmentActivityType -> FulfillmentActivity
FulfillmentActivity'
    { $sel:codeHook:FulfillmentActivity' :: Maybe CodeHook
codeHook = Maybe 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 :: (Maybe CodeHook -> f (Maybe CodeHook))
-> FulfillmentActivity -> f FulfillmentActivity
fulfillmentActivity_codeHook = (FulfillmentActivity -> Maybe CodeHook)
-> (FulfillmentActivity -> Maybe CodeHook -> FulfillmentActivity)
-> Lens
     FulfillmentActivity
     FulfillmentActivity
     (Maybe CodeHook)
     (Maybe 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 :: (FulfillmentActivityType -> f FulfillmentActivityType)
-> FulfillmentActivity -> f FulfillmentActivity
fulfillmentActivity_type = (FulfillmentActivity -> FulfillmentActivityType)
-> (FulfillmentActivity
    -> FulfillmentActivityType -> FulfillmentActivity)
-> Lens
     FulfillmentActivity
     FulfillmentActivity
     FulfillmentActivityType
     FulfillmentActivityType
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 Core.FromJSON FulfillmentActivity where
  parseJSON :: Value -> Parser FulfillmentActivity
parseJSON =
    String
-> (Object -> Parser FulfillmentActivity)
-> Value
-> Parser FulfillmentActivity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FulfillmentActivity"
      ( \Object
x ->
          Maybe CodeHook -> FulfillmentActivityType -> FulfillmentActivity
FulfillmentActivity'
            (Maybe CodeHook -> FulfillmentActivityType -> FulfillmentActivity)
-> Parser (Maybe CodeHook)
-> Parser (FulfillmentActivityType -> FulfillmentActivity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe CodeHook)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"codeHook")
            Parser (FulfillmentActivityType -> FulfillmentActivity)
-> Parser FulfillmentActivityType -> Parser FulfillmentActivity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser FulfillmentActivityType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable FulfillmentActivity

instance Prelude.NFData FulfillmentActivity

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"codeHook" Text -> CodeHook -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (CodeHook -> Pair) -> Maybe CodeHook -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CodeHook
codeHook,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> FulfillmentActivityType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= FulfillmentActivityType
type')
          ]
      )