{-# 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.Kendra.Types.HookConfiguration
-- 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.Kendra.Types.HookConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Kendra.Types.DocumentAttributeCondition
import qualified Amazonka.Prelude as Prelude

-- | Provides the configuration information for invoking a Lambda function in
-- Lambda to alter document metadata and content when ingesting documents
-- into Amazon Kendra. You can configure your Lambda function using
-- <https://docs.aws.amazon.com/kendra/latest/dg/API_CustomDocumentEnrichmentConfiguration.html PreExtractionHookConfiguration>
-- if you want to apply advanced alterations on the original or raw
-- documents. If you want to apply advanced alterations on the Amazon
-- Kendra structured documents, you must configure your Lambda function
-- using
-- <https://docs.aws.amazon.com/kendra/latest/dg/API_CustomDocumentEnrichmentConfiguration.html PostExtractionHookConfiguration>.
-- You can only invoke one Lambda function. However, this function can
-- invoke other functions it requires.
--
-- For more information, see
-- <https://docs.aws.amazon.com/kendra/latest/dg/custom-document-enrichment.html Customizing document metadata during the ingestion process>.
--
-- /See:/ 'newHookConfiguration' smart constructor.
data HookConfiguration = HookConfiguration'
  { -- | The condition used for when a Lambda function should be invoked.
    --
    -- For example, you can specify a condition that if there are empty
    -- date-time values, then Amazon Kendra should invoke a function that
    -- inserts the current date-time.
    HookConfiguration -> Maybe DocumentAttributeCondition
invocationCondition :: Prelude.Maybe DocumentAttributeCondition,
    -- | The Amazon Resource Name (ARN) of a role with permission to run a Lambda
    -- function during ingestion. For more information, see
    -- <https://docs.aws.amazon.com/kendra/latest/dg/iam-roles.html IAM roles for Amazon Kendra>.
    HookConfiguration -> Text
lambdaArn :: Prelude.Text,
    -- | Stores the original, raw documents or the structured, parsed documents
    -- before and after altering them. For more information, see
    -- <https://docs.aws.amazon.com/kendra/latest/dg/custom-document-enrichment.html#cde-data-contracts-lambda Data contracts for Lambda functions>.
    HookConfiguration -> Text
s3Bucket :: Prelude.Text
  }
  deriving (HookConfiguration -> HookConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HookConfiguration -> HookConfiguration -> Bool
$c/= :: HookConfiguration -> HookConfiguration -> Bool
== :: HookConfiguration -> HookConfiguration -> Bool
$c== :: HookConfiguration -> HookConfiguration -> Bool
Prelude.Eq, ReadPrec [HookConfiguration]
ReadPrec HookConfiguration
Int -> ReadS HookConfiguration
ReadS [HookConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HookConfiguration]
$creadListPrec :: ReadPrec [HookConfiguration]
readPrec :: ReadPrec HookConfiguration
$creadPrec :: ReadPrec HookConfiguration
readList :: ReadS [HookConfiguration]
$creadList :: ReadS [HookConfiguration]
readsPrec :: Int -> ReadS HookConfiguration
$creadsPrec :: Int -> ReadS HookConfiguration
Prelude.Read, Int -> HookConfiguration -> ShowS
[HookConfiguration] -> ShowS
HookConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HookConfiguration] -> ShowS
$cshowList :: [HookConfiguration] -> ShowS
show :: HookConfiguration -> String
$cshow :: HookConfiguration -> String
showsPrec :: Int -> HookConfiguration -> ShowS
$cshowsPrec :: Int -> HookConfiguration -> ShowS
Prelude.Show, forall x. Rep HookConfiguration x -> HookConfiguration
forall x. HookConfiguration -> Rep HookConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HookConfiguration x -> HookConfiguration
$cfrom :: forall x. HookConfiguration -> Rep HookConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'HookConfiguration' 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:
--
-- 'invocationCondition', 'hookConfiguration_invocationCondition' - The condition used for when a Lambda function should be invoked.
--
-- For example, you can specify a condition that if there are empty
-- date-time values, then Amazon Kendra should invoke a function that
-- inserts the current date-time.
--
-- 'lambdaArn', 'hookConfiguration_lambdaArn' - The Amazon Resource Name (ARN) of a role with permission to run a Lambda
-- function during ingestion. For more information, see
-- <https://docs.aws.amazon.com/kendra/latest/dg/iam-roles.html IAM roles for Amazon Kendra>.
--
-- 's3Bucket', 'hookConfiguration_s3Bucket' - Stores the original, raw documents or the structured, parsed documents
-- before and after altering them. For more information, see
-- <https://docs.aws.amazon.com/kendra/latest/dg/custom-document-enrichment.html#cde-data-contracts-lambda Data contracts for Lambda functions>.
newHookConfiguration ::
  -- | 'lambdaArn'
  Prelude.Text ->
  -- | 's3Bucket'
  Prelude.Text ->
  HookConfiguration
newHookConfiguration :: Text -> Text -> HookConfiguration
newHookConfiguration Text
pLambdaArn_ Text
pS3Bucket_ =
  HookConfiguration'
    { $sel:invocationCondition:HookConfiguration' :: Maybe DocumentAttributeCondition
invocationCondition =
        forall a. Maybe a
Prelude.Nothing,
      $sel:lambdaArn:HookConfiguration' :: Text
lambdaArn = Text
pLambdaArn_,
      $sel:s3Bucket:HookConfiguration' :: Text
s3Bucket = Text
pS3Bucket_
    }

-- | The condition used for when a Lambda function should be invoked.
--
-- For example, you can specify a condition that if there are empty
-- date-time values, then Amazon Kendra should invoke a function that
-- inserts the current date-time.
hookConfiguration_invocationCondition :: Lens.Lens' HookConfiguration (Prelude.Maybe DocumentAttributeCondition)
hookConfiguration_invocationCondition :: Lens' HookConfiguration (Maybe DocumentAttributeCondition)
hookConfiguration_invocationCondition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HookConfiguration' {Maybe DocumentAttributeCondition
invocationCondition :: Maybe DocumentAttributeCondition
$sel:invocationCondition:HookConfiguration' :: HookConfiguration -> Maybe DocumentAttributeCondition
invocationCondition} -> Maybe DocumentAttributeCondition
invocationCondition) (\s :: HookConfiguration
s@HookConfiguration' {} Maybe DocumentAttributeCondition
a -> HookConfiguration
s {$sel:invocationCondition:HookConfiguration' :: Maybe DocumentAttributeCondition
invocationCondition = Maybe DocumentAttributeCondition
a} :: HookConfiguration)

-- | The Amazon Resource Name (ARN) of a role with permission to run a Lambda
-- function during ingestion. For more information, see
-- <https://docs.aws.amazon.com/kendra/latest/dg/iam-roles.html IAM roles for Amazon Kendra>.
hookConfiguration_lambdaArn :: Lens.Lens' HookConfiguration Prelude.Text
hookConfiguration_lambdaArn :: Lens' HookConfiguration Text
hookConfiguration_lambdaArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HookConfiguration' {Text
lambdaArn :: Text
$sel:lambdaArn:HookConfiguration' :: HookConfiguration -> Text
lambdaArn} -> Text
lambdaArn) (\s :: HookConfiguration
s@HookConfiguration' {} Text
a -> HookConfiguration
s {$sel:lambdaArn:HookConfiguration' :: Text
lambdaArn = Text
a} :: HookConfiguration)

-- | Stores the original, raw documents or the structured, parsed documents
-- before and after altering them. For more information, see
-- <https://docs.aws.amazon.com/kendra/latest/dg/custom-document-enrichment.html#cde-data-contracts-lambda Data contracts for Lambda functions>.
hookConfiguration_s3Bucket :: Lens.Lens' HookConfiguration Prelude.Text
hookConfiguration_s3Bucket :: Lens' HookConfiguration Text
hookConfiguration_s3Bucket = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HookConfiguration' {Text
s3Bucket :: Text
$sel:s3Bucket:HookConfiguration' :: HookConfiguration -> Text
s3Bucket} -> Text
s3Bucket) (\s :: HookConfiguration
s@HookConfiguration' {} Text
a -> HookConfiguration
s {$sel:s3Bucket:HookConfiguration' :: Text
s3Bucket = Text
a} :: HookConfiguration)

instance Data.FromJSON HookConfiguration where
  parseJSON :: Value -> Parser HookConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HookConfiguration"
      ( \Object
x ->
          Maybe DocumentAttributeCondition
-> Text -> Text -> HookConfiguration
HookConfiguration'
            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
"InvocationCondition")
            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
"LambdaArn")
            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
"S3Bucket")
      )

instance Prelude.Hashable HookConfiguration where
  hashWithSalt :: Int -> HookConfiguration -> Int
hashWithSalt Int
_salt HookConfiguration' {Maybe DocumentAttributeCondition
Text
s3Bucket :: Text
lambdaArn :: Text
invocationCondition :: Maybe DocumentAttributeCondition
$sel:s3Bucket:HookConfiguration' :: HookConfiguration -> Text
$sel:lambdaArn:HookConfiguration' :: HookConfiguration -> Text
$sel:invocationCondition:HookConfiguration' :: HookConfiguration -> Maybe DocumentAttributeCondition
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DocumentAttributeCondition
invocationCondition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
lambdaArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
s3Bucket

instance Prelude.NFData HookConfiguration where
  rnf :: HookConfiguration -> ()
rnf HookConfiguration' {Maybe DocumentAttributeCondition
Text
s3Bucket :: Text
lambdaArn :: Text
invocationCondition :: Maybe DocumentAttributeCondition
$sel:s3Bucket:HookConfiguration' :: HookConfiguration -> Text
$sel:lambdaArn:HookConfiguration' :: HookConfiguration -> Text
$sel:invocationCondition:HookConfiguration' :: HookConfiguration -> Maybe DocumentAttributeCondition
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe DocumentAttributeCondition
invocationCondition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
lambdaArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
s3Bucket

instance Data.ToJSON HookConfiguration where
  toJSON :: HookConfiguration -> Value
toJSON HookConfiguration' {Maybe DocumentAttributeCondition
Text
s3Bucket :: Text
lambdaArn :: Text
invocationCondition :: Maybe DocumentAttributeCondition
$sel:s3Bucket:HookConfiguration' :: HookConfiguration -> Text
$sel:lambdaArn:HookConfiguration' :: HookConfiguration -> Text
$sel:invocationCondition:HookConfiguration' :: HookConfiguration -> Maybe DocumentAttributeCondition
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"InvocationCondition" 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 DocumentAttributeCondition
invocationCondition,
            forall a. a -> Maybe a
Prelude.Just (Key
"LambdaArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
lambdaArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"S3Bucket" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
s3Bucket)
          ]
      )