{-# 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.OutputContext
-- 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.OutputContext where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The specification of an output context that is set when an intent is
-- fulfilled.
--
-- /See:/ 'newOutputContext' smart constructor.
data OutputContext = OutputContext'
  { -- | The name of the context.
    OutputContext -> Text
name :: Prelude.Text,
    -- | The number of seconds that the context should be active after it is
    -- first sent in a @PostContent@ or @PostText@ response. You can set the
    -- value between 5 and 86,400 seconds (24 hours).
    OutputContext -> Natural
timeToLiveInSeconds :: Prelude.Natural,
    -- | The number of conversation turns that the context should be active. A
    -- conversation turn is one @PostContent@ or @PostText@ request and the
    -- corresponding response from Amazon Lex.
    OutputContext -> Natural
turnsToLive :: Prelude.Natural
  }
  deriving (OutputContext -> OutputContext -> Bool
(OutputContext -> OutputContext -> Bool)
-> (OutputContext -> OutputContext -> Bool) -> Eq OutputContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OutputContext -> OutputContext -> Bool
$c/= :: OutputContext -> OutputContext -> Bool
== :: OutputContext -> OutputContext -> Bool
$c== :: OutputContext -> OutputContext -> Bool
Prelude.Eq, ReadPrec [OutputContext]
ReadPrec OutputContext
Int -> ReadS OutputContext
ReadS [OutputContext]
(Int -> ReadS OutputContext)
-> ReadS [OutputContext]
-> ReadPrec OutputContext
-> ReadPrec [OutputContext]
-> Read OutputContext
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OutputContext]
$creadListPrec :: ReadPrec [OutputContext]
readPrec :: ReadPrec OutputContext
$creadPrec :: ReadPrec OutputContext
readList :: ReadS [OutputContext]
$creadList :: ReadS [OutputContext]
readsPrec :: Int -> ReadS OutputContext
$creadsPrec :: Int -> ReadS OutputContext
Prelude.Read, Int -> OutputContext -> ShowS
[OutputContext] -> ShowS
OutputContext -> String
(Int -> OutputContext -> ShowS)
-> (OutputContext -> String)
-> ([OutputContext] -> ShowS)
-> Show OutputContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OutputContext] -> ShowS
$cshowList :: [OutputContext] -> ShowS
show :: OutputContext -> String
$cshow :: OutputContext -> String
showsPrec :: Int -> OutputContext -> ShowS
$cshowsPrec :: Int -> OutputContext -> ShowS
Prelude.Show, (forall x. OutputContext -> Rep OutputContext x)
-> (forall x. Rep OutputContext x -> OutputContext)
-> Generic OutputContext
forall x. Rep OutputContext x -> OutputContext
forall x. OutputContext -> Rep OutputContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OutputContext x -> OutputContext
$cfrom :: forall x. OutputContext -> Rep OutputContext x
Prelude.Generic)

-- |
-- Create a value of 'OutputContext' 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:
--
-- 'name', 'outputContext_name' - The name of the context.
--
-- 'timeToLiveInSeconds', 'outputContext_timeToLiveInSeconds' - The number of seconds that the context should be active after it is
-- first sent in a @PostContent@ or @PostText@ response. You can set the
-- value between 5 and 86,400 seconds (24 hours).
--
-- 'turnsToLive', 'outputContext_turnsToLive' - The number of conversation turns that the context should be active. A
-- conversation turn is one @PostContent@ or @PostText@ request and the
-- corresponding response from Amazon Lex.
newOutputContext ::
  -- | 'name'
  Prelude.Text ->
  -- | 'timeToLiveInSeconds'
  Prelude.Natural ->
  -- | 'turnsToLive'
  Prelude.Natural ->
  OutputContext
newOutputContext :: Text -> Natural -> Natural -> OutputContext
newOutputContext
  Text
pName_
  Natural
pTimeToLiveInSeconds_
  Natural
pTurnsToLive_ =
    OutputContext' :: Text -> Natural -> Natural -> OutputContext
OutputContext'
      { $sel:name:OutputContext' :: Text
name = Text
pName_,
        $sel:timeToLiveInSeconds:OutputContext' :: Natural
timeToLiveInSeconds = Natural
pTimeToLiveInSeconds_,
        $sel:turnsToLive:OutputContext' :: Natural
turnsToLive = Natural
pTurnsToLive_
      }

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

-- | The number of seconds that the context should be active after it is
-- first sent in a @PostContent@ or @PostText@ response. You can set the
-- value between 5 and 86,400 seconds (24 hours).
outputContext_timeToLiveInSeconds :: Lens.Lens' OutputContext Prelude.Natural
outputContext_timeToLiveInSeconds :: (Natural -> f Natural) -> OutputContext -> f OutputContext
outputContext_timeToLiveInSeconds = (OutputContext -> Natural)
-> (OutputContext -> Natural -> OutputContext)
-> Lens OutputContext OutputContext Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OutputContext' {Natural
timeToLiveInSeconds :: Natural
$sel:timeToLiveInSeconds:OutputContext' :: OutputContext -> Natural
timeToLiveInSeconds} -> Natural
timeToLiveInSeconds) (\s :: OutputContext
s@OutputContext' {} Natural
a -> OutputContext
s {$sel:timeToLiveInSeconds:OutputContext' :: Natural
timeToLiveInSeconds = Natural
a} :: OutputContext)

-- | The number of conversation turns that the context should be active. A
-- conversation turn is one @PostContent@ or @PostText@ request and the
-- corresponding response from Amazon Lex.
outputContext_turnsToLive :: Lens.Lens' OutputContext Prelude.Natural
outputContext_turnsToLive :: (Natural -> f Natural) -> OutputContext -> f OutputContext
outputContext_turnsToLive = (OutputContext -> Natural)
-> (OutputContext -> Natural -> OutputContext)
-> Lens OutputContext OutputContext Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OutputContext' {Natural
turnsToLive :: Natural
$sel:turnsToLive:OutputContext' :: OutputContext -> Natural
turnsToLive} -> Natural
turnsToLive) (\s :: OutputContext
s@OutputContext' {} Natural
a -> OutputContext
s {$sel:turnsToLive:OutputContext' :: Natural
turnsToLive = Natural
a} :: OutputContext)

instance Core.FromJSON OutputContext where
  parseJSON :: Value -> Parser OutputContext
parseJSON =
    String
-> (Object -> Parser OutputContext)
-> Value
-> Parser OutputContext
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OutputContext"
      ( \Object
x ->
          Text -> Natural -> Natural -> OutputContext
OutputContext'
            (Text -> Natural -> Natural -> OutputContext)
-> Parser Text -> Parser (Natural -> Natural -> OutputContext)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name")
            Parser (Natural -> Natural -> OutputContext)
-> Parser Natural -> Parser (Natural -> OutputContext)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"timeToLiveInSeconds")
            Parser (Natural -> OutputContext)
-> Parser Natural -> Parser OutputContext
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"turnsToLive")
      )

instance Prelude.Hashable OutputContext

instance Prelude.NFData OutputContext

instance Core.ToJSON OutputContext where
  toJSON :: OutputContext -> Value
toJSON OutputContext' {Natural
Text
turnsToLive :: Natural
timeToLiveInSeconds :: Natural
name :: Text
$sel:turnsToLive:OutputContext' :: OutputContext -> Natural
$sel:timeToLiveInSeconds:OutputContext' :: OutputContext -> Natural
$sel:name:OutputContext' :: OutputContext -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"timeToLiveInSeconds" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
timeToLiveInSeconds),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"turnsToLive" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
turnsToLive)
          ]
      )