{-# 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.ResponseSpecification
-- 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.ResponseSpecification 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.MessageGroup
import qualified Amazonka.Prelude as Prelude

-- | Specifies a list of message groups that Amazon Lex uses to respond the
-- user input.
--
-- /See:/ 'newResponseSpecification' smart constructor.
data ResponseSpecification = ResponseSpecification'
  { -- | Indicates whether the user can interrupt a speech response from Amazon
    -- Lex.
    ResponseSpecification -> Maybe Bool
allowInterrupt :: Prelude.Maybe Prelude.Bool,
    -- | A collection of responses that Amazon Lex can send to the user. Amazon
    -- Lex chooses the actual response to send at runtime.
    ResponseSpecification -> NonEmpty MessageGroup
messageGroups :: Prelude.NonEmpty MessageGroup
  }
  deriving (ResponseSpecification -> ResponseSpecification -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResponseSpecification -> ResponseSpecification -> Bool
$c/= :: ResponseSpecification -> ResponseSpecification -> Bool
== :: ResponseSpecification -> ResponseSpecification -> Bool
$c== :: ResponseSpecification -> ResponseSpecification -> Bool
Prelude.Eq, ReadPrec [ResponseSpecification]
ReadPrec ResponseSpecification
Int -> ReadS ResponseSpecification
ReadS [ResponseSpecification]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResponseSpecification]
$creadListPrec :: ReadPrec [ResponseSpecification]
readPrec :: ReadPrec ResponseSpecification
$creadPrec :: ReadPrec ResponseSpecification
readList :: ReadS [ResponseSpecification]
$creadList :: ReadS [ResponseSpecification]
readsPrec :: Int -> ReadS ResponseSpecification
$creadsPrec :: Int -> ReadS ResponseSpecification
Prelude.Read, Int -> ResponseSpecification -> ShowS
[ResponseSpecification] -> ShowS
ResponseSpecification -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResponseSpecification] -> ShowS
$cshowList :: [ResponseSpecification] -> ShowS
show :: ResponseSpecification -> String
$cshow :: ResponseSpecification -> String
showsPrec :: Int -> ResponseSpecification -> ShowS
$cshowsPrec :: Int -> ResponseSpecification -> ShowS
Prelude.Show, forall x. Rep ResponseSpecification x -> ResponseSpecification
forall x. ResponseSpecification -> Rep ResponseSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResponseSpecification x -> ResponseSpecification
$cfrom :: forall x. ResponseSpecification -> Rep ResponseSpecification x
Prelude.Generic)

-- |
-- Create a value of 'ResponseSpecification' 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:
--
-- 'allowInterrupt', 'responseSpecification_allowInterrupt' - Indicates whether the user can interrupt a speech response from Amazon
-- Lex.
--
-- 'messageGroups', 'responseSpecification_messageGroups' - A collection of responses that Amazon Lex can send to the user. Amazon
-- Lex chooses the actual response to send at runtime.
newResponseSpecification ::
  -- | 'messageGroups'
  Prelude.NonEmpty MessageGroup ->
  ResponseSpecification
newResponseSpecification :: NonEmpty MessageGroup -> ResponseSpecification
newResponseSpecification NonEmpty MessageGroup
pMessageGroups_ =
  ResponseSpecification'
    { $sel:allowInterrupt:ResponseSpecification' :: Maybe Bool
allowInterrupt =
        forall a. Maybe a
Prelude.Nothing,
      $sel:messageGroups:ResponseSpecification' :: NonEmpty MessageGroup
messageGroups = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty MessageGroup
pMessageGroups_
    }

-- | Indicates whether the user can interrupt a speech response from Amazon
-- Lex.
responseSpecification_allowInterrupt :: Lens.Lens' ResponseSpecification (Prelude.Maybe Prelude.Bool)
responseSpecification_allowInterrupt :: Lens' ResponseSpecification (Maybe Bool)
responseSpecification_allowInterrupt = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResponseSpecification' {Maybe Bool
allowInterrupt :: Maybe Bool
$sel:allowInterrupt:ResponseSpecification' :: ResponseSpecification -> Maybe Bool
allowInterrupt} -> Maybe Bool
allowInterrupt) (\s :: ResponseSpecification
s@ResponseSpecification' {} Maybe Bool
a -> ResponseSpecification
s {$sel:allowInterrupt:ResponseSpecification' :: Maybe Bool
allowInterrupt = Maybe Bool
a} :: ResponseSpecification)

-- | A collection of responses that Amazon Lex can send to the user. Amazon
-- Lex chooses the actual response to send at runtime.
responseSpecification_messageGroups :: Lens.Lens' ResponseSpecification (Prelude.NonEmpty MessageGroup)
responseSpecification_messageGroups :: Lens' ResponseSpecification (NonEmpty MessageGroup)
responseSpecification_messageGroups = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResponseSpecification' {NonEmpty MessageGroup
messageGroups :: NonEmpty MessageGroup
$sel:messageGroups:ResponseSpecification' :: ResponseSpecification -> NonEmpty MessageGroup
messageGroups} -> NonEmpty MessageGroup
messageGroups) (\s :: ResponseSpecification
s@ResponseSpecification' {} NonEmpty MessageGroup
a -> ResponseSpecification
s {$sel:messageGroups:ResponseSpecification' :: NonEmpty MessageGroup
messageGroups = NonEmpty MessageGroup
a} :: ResponseSpecification) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON ResponseSpecification where
  parseJSON :: Value -> Parser ResponseSpecification
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ResponseSpecification"
      ( \Object
x ->
          Maybe Bool -> NonEmpty MessageGroup -> ResponseSpecification
ResponseSpecification'
            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
"allowInterrupt")
            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
"messageGroups")
      )

instance Prelude.Hashable ResponseSpecification where
  hashWithSalt :: Int -> ResponseSpecification -> Int
hashWithSalt Int
_salt ResponseSpecification' {Maybe Bool
NonEmpty MessageGroup
messageGroups :: NonEmpty MessageGroup
allowInterrupt :: Maybe Bool
$sel:messageGroups:ResponseSpecification' :: ResponseSpecification -> NonEmpty MessageGroup
$sel:allowInterrupt:ResponseSpecification' :: ResponseSpecification -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
allowInterrupt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty MessageGroup
messageGroups

instance Prelude.NFData ResponseSpecification where
  rnf :: ResponseSpecification -> ()
rnf ResponseSpecification' {Maybe Bool
NonEmpty MessageGroup
messageGroups :: NonEmpty MessageGroup
allowInterrupt :: Maybe Bool
$sel:messageGroups:ResponseSpecification' :: ResponseSpecification -> NonEmpty MessageGroup
$sel:allowInterrupt:ResponseSpecification' :: ResponseSpecification -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
allowInterrupt
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty MessageGroup
messageGroups

instance Data.ToJSON ResponseSpecification where
  toJSON :: ResponseSpecification -> Value
toJSON ResponseSpecification' {Maybe Bool
NonEmpty MessageGroup
messageGroups :: NonEmpty MessageGroup
allowInterrupt :: Maybe Bool
$sel:messageGroups:ResponseSpecification' :: ResponseSpecification -> NonEmpty MessageGroup
$sel:allowInterrupt:ResponseSpecification' :: ResponseSpecification -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"allowInterrupt" 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 Bool
allowInterrupt,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"messageGroups" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty MessageGroup
messageGroups)
          ]
      )