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

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

-- | Describes a session context that is activated when an intent is
-- fulfilled.
--
-- /See:/ 'newOutputContext' smart constructor.
data OutputContext = OutputContext'
  { -- | The name of the output context.
    OutputContext -> Text
name :: Prelude.Text,
    -- | The amount of time, in seconds, that the output context should remain
    -- active. The time is figured from the first time the context is sent to
    -- the user.
    OutputContext -> Natural
timeToLiveInSeconds :: Prelude.Natural,
    -- | The number of conversation turns that the output context should remain
    -- active. The number of turns is counted from the first time that the
    -- context is sent to the user.
    OutputContext -> Natural
turnsToLive :: Prelude.Natural
  }
  deriving (OutputContext -> OutputContext -> Bool
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]
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
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. 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 output context.
--
-- 'timeToLiveInSeconds', 'outputContext_timeToLiveInSeconds' - The amount of time, in seconds, that the output context should remain
-- active. The time is figured from the first time the context is sent to
-- the user.
--
-- 'turnsToLive', 'outputContext_turnsToLive' - The number of conversation turns that the output context should remain
-- active. The number of turns is counted from the first time that the
-- context is sent to the user.
newOutputContext ::
  -- | 'name'
  Prelude.Text ->
  -- | 'timeToLiveInSeconds'
  Prelude.Natural ->
  -- | 'turnsToLive'
  Prelude.Natural ->
  OutputContext
newOutputContext :: Text -> Natural -> Natural -> OutputContext
newOutputContext
  Text
pName_
  Natural
pTimeToLiveInSeconds_
  Natural
pTurnsToLive_ =
    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 output context.
outputContext_name :: Lens.Lens' OutputContext Prelude.Text
outputContext_name :: Lens' OutputContext Text
outputContext_name = 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 amount of time, in seconds, that the output context should remain
-- active. The time is figured from the first time the context is sent to
-- the user.
outputContext_timeToLiveInSeconds :: Lens.Lens' OutputContext Prelude.Natural
outputContext_timeToLiveInSeconds :: Lens' OutputContext Natural
outputContext_timeToLiveInSeconds = 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 output context should remain
-- active. The number of turns is counted from the first time that the
-- context is sent to the user.
outputContext_turnsToLive :: Lens.Lens' OutputContext Prelude.Natural
outputContext_turnsToLive :: Lens' OutputContext Natural
outputContext_turnsToLive = 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 Data.FromJSON OutputContext where
  parseJSON :: Value -> Parser OutputContext
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"OutputContext"
      ( \Object
x ->
          Text -> Natural -> Natural -> OutputContext
OutputContext'
            forall (f :: * -> *) a b. Functor 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
"timeToLiveInSeconds")
            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
"turnsToLive")
      )

instance Prelude.Hashable OutputContext where
  hashWithSalt :: Int -> OutputContext -> Int
hashWithSalt Int
_salt OutputContext' {Natural
Text
turnsToLive :: Natural
timeToLiveInSeconds :: Natural
name :: Text
$sel:turnsToLive:OutputContext' :: OutputContext -> Natural
$sel:timeToLiveInSeconds:OutputContext' :: OutputContext -> Natural
$sel:name:OutputContext' :: OutputContext -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
timeToLiveInSeconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
turnsToLive

instance Prelude.NFData OutputContext where
  rnf :: OutputContext -> ()
rnf OutputContext' {Natural
Text
turnsToLive :: Natural
timeToLiveInSeconds :: Natural
name :: Text
$sel:turnsToLive:OutputContext' :: OutputContext -> Natural
$sel:timeToLiveInSeconds:OutputContext' :: OutputContext -> Natural
$sel:name:OutputContext' :: OutputContext -> Text
..} =
    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 Natural
timeToLiveInSeconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
turnsToLive

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ 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
"timeToLiveInSeconds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
timeToLiveInSeconds),
            forall a. a -> Maybe a
Prelude.Just (Key
"turnsToLive" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
turnsToLive)
          ]
      )