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

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

-- | Specifies a Lambda function that verifies requests to a bot or fulfills
-- the user\'s request to a bot..
--
-- /See:/ 'newCodeHook' smart constructor.
data CodeHook = CodeHook'
  { -- | The Amazon Resource Name (ARN) of the Lambda function.
    CodeHook -> Text
uri :: Prelude.Text,
    -- | The version of the request-response that you want Amazon Lex to use to
    -- invoke your Lambda function. For more information, see using-lambda.
    CodeHook -> Text
messageVersion :: Prelude.Text
  }
  deriving (CodeHook -> CodeHook -> Bool
(CodeHook -> CodeHook -> Bool)
-> (CodeHook -> CodeHook -> Bool) -> Eq CodeHook
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CodeHook -> CodeHook -> Bool
$c/= :: CodeHook -> CodeHook -> Bool
== :: CodeHook -> CodeHook -> Bool
$c== :: CodeHook -> CodeHook -> Bool
Prelude.Eq, ReadPrec [CodeHook]
ReadPrec CodeHook
Int -> ReadS CodeHook
ReadS [CodeHook]
(Int -> ReadS CodeHook)
-> ReadS [CodeHook]
-> ReadPrec CodeHook
-> ReadPrec [CodeHook]
-> Read CodeHook
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CodeHook]
$creadListPrec :: ReadPrec [CodeHook]
readPrec :: ReadPrec CodeHook
$creadPrec :: ReadPrec CodeHook
readList :: ReadS [CodeHook]
$creadList :: ReadS [CodeHook]
readsPrec :: Int -> ReadS CodeHook
$creadsPrec :: Int -> ReadS CodeHook
Prelude.Read, Int -> CodeHook -> ShowS
[CodeHook] -> ShowS
CodeHook -> String
(Int -> CodeHook -> ShowS)
-> (CodeHook -> String) -> ([CodeHook] -> ShowS) -> Show CodeHook
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CodeHook] -> ShowS
$cshowList :: [CodeHook] -> ShowS
show :: CodeHook -> String
$cshow :: CodeHook -> String
showsPrec :: Int -> CodeHook -> ShowS
$cshowsPrec :: Int -> CodeHook -> ShowS
Prelude.Show, (forall x. CodeHook -> Rep CodeHook x)
-> (forall x. Rep CodeHook x -> CodeHook) -> Generic CodeHook
forall x. Rep CodeHook x -> CodeHook
forall x. CodeHook -> Rep CodeHook x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CodeHook x -> CodeHook
$cfrom :: forall x. CodeHook -> Rep CodeHook x
Prelude.Generic)

-- |
-- Create a value of 'CodeHook' 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:
--
-- 'uri', 'codeHook_uri' - The Amazon Resource Name (ARN) of the Lambda function.
--
-- 'messageVersion', 'codeHook_messageVersion' - The version of the request-response that you want Amazon Lex to use to
-- invoke your Lambda function. For more information, see using-lambda.
newCodeHook ::
  -- | 'uri'
  Prelude.Text ->
  -- | 'messageVersion'
  Prelude.Text ->
  CodeHook
newCodeHook :: Text -> Text -> CodeHook
newCodeHook Text
pUri_ Text
pMessageVersion_ =
  CodeHook' :: Text -> Text -> CodeHook
CodeHook'
    { $sel:uri:CodeHook' :: Text
uri = Text
pUri_,
      $sel:messageVersion:CodeHook' :: Text
messageVersion = Text
pMessageVersion_
    }

-- | The Amazon Resource Name (ARN) of the Lambda function.
codeHook_uri :: Lens.Lens' CodeHook Prelude.Text
codeHook_uri :: (Text -> f Text) -> CodeHook -> f CodeHook
codeHook_uri = (CodeHook -> Text)
-> (CodeHook -> Text -> CodeHook)
-> Lens CodeHook CodeHook Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeHook' {Text
uri :: Text
$sel:uri:CodeHook' :: CodeHook -> Text
uri} -> Text
uri) (\s :: CodeHook
s@CodeHook' {} Text
a -> CodeHook
s {$sel:uri:CodeHook' :: Text
uri = Text
a} :: CodeHook)

-- | The version of the request-response that you want Amazon Lex to use to
-- invoke your Lambda function. For more information, see using-lambda.
codeHook_messageVersion :: Lens.Lens' CodeHook Prelude.Text
codeHook_messageVersion :: (Text -> f Text) -> CodeHook -> f CodeHook
codeHook_messageVersion = (CodeHook -> Text)
-> (CodeHook -> Text -> CodeHook)
-> Lens CodeHook CodeHook Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeHook' {Text
messageVersion :: Text
$sel:messageVersion:CodeHook' :: CodeHook -> Text
messageVersion} -> Text
messageVersion) (\s :: CodeHook
s@CodeHook' {} Text
a -> CodeHook
s {$sel:messageVersion:CodeHook' :: Text
messageVersion = Text
a} :: CodeHook)

instance Core.FromJSON CodeHook where
  parseJSON :: Value -> Parser CodeHook
parseJSON =
    String -> (Object -> Parser CodeHook) -> Value -> Parser CodeHook
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CodeHook"
      ( \Object
x ->
          Text -> Text -> CodeHook
CodeHook'
            (Text -> Text -> CodeHook)
-> Parser Text -> Parser (Text -> CodeHook)
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
"uri")
            Parser (Text -> CodeHook) -> Parser Text -> Parser CodeHook
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"messageVersion")
      )

instance Prelude.Hashable CodeHook

instance Prelude.NFData CodeHook

instance Core.ToJSON CodeHook where
  toJSON :: CodeHook -> Value
toJSON CodeHook' {Text
messageVersion :: Text
uri :: Text
$sel:messageVersion:CodeHook' :: CodeHook -> Text
$sel:uri:CodeHook' :: CodeHook -> 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
"uri" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
uri),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"messageVersion" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
messageVersion)
          ]
      )