{-# 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.DocumentAttributeCondition
-- 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.DocumentAttributeCondition 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.ConditionOperator
import Amazonka.Kendra.Types.DocumentAttributeValue
import qualified Amazonka.Prelude as Prelude

-- | The condition used for the target document attribute or metadata field
-- when ingesting documents into Amazon Kendra. You use this with
-- <https://docs.aws.amazon.com/kendra/latest/dg/API_DocumentAttributeTarget.html DocumentAttributeTarget to apply the condition>.
--
-- For example, you can create the \'Department\' target field and have it
-- prefill department names associated with the documents based on
-- information in the \'Source_URI\' field. Set the condition that if the
-- \'Source_URI\' field contains \'financial\' in its URI value, then
-- prefill the target field \'Department\' with the target value
-- \'Finance\' for the document.
--
-- Amazon Kendra cannot create a target field if it has not already been
-- created as an index field. After you create your index field, you can
-- create a document metadata field using @DocumentAttributeTarget@. Amazon
-- Kendra then will map your newly created metadata field to your index
-- field.
--
-- /See:/ 'newDocumentAttributeCondition' smart constructor.
data DocumentAttributeCondition = DocumentAttributeCondition'
  { -- | The value used by the operator.
    --
    -- For example, you can specify the value \'financial\' for strings in the
    -- \'Source_URI\' field that partially match or contain this value.
    DocumentAttributeCondition -> Maybe DocumentAttributeValue
conditionOnValue :: Prelude.Maybe DocumentAttributeValue,
    -- | The identifier of the document attribute used for the condition.
    --
    -- For example, \'Source_URI\' could be an identifier for the attribute or
    -- metadata field that contains source URIs associated with the documents.
    --
    -- Amazon Kendra currently does not support @_document_body@ as an
    -- attribute key used for the condition.
    DocumentAttributeCondition -> Text
conditionDocumentAttributeKey :: Prelude.Text,
    -- | The condition operator.
    --
    -- For example, you can use \'Contains\' to partially match a string.
    DocumentAttributeCondition -> ConditionOperator
operator :: ConditionOperator
  }
  deriving (DocumentAttributeCondition -> DocumentAttributeCondition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DocumentAttributeCondition -> DocumentAttributeCondition -> Bool
$c/= :: DocumentAttributeCondition -> DocumentAttributeCondition -> Bool
== :: DocumentAttributeCondition -> DocumentAttributeCondition -> Bool
$c== :: DocumentAttributeCondition -> DocumentAttributeCondition -> Bool
Prelude.Eq, ReadPrec [DocumentAttributeCondition]
ReadPrec DocumentAttributeCondition
Int -> ReadS DocumentAttributeCondition
ReadS [DocumentAttributeCondition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DocumentAttributeCondition]
$creadListPrec :: ReadPrec [DocumentAttributeCondition]
readPrec :: ReadPrec DocumentAttributeCondition
$creadPrec :: ReadPrec DocumentAttributeCondition
readList :: ReadS [DocumentAttributeCondition]
$creadList :: ReadS [DocumentAttributeCondition]
readsPrec :: Int -> ReadS DocumentAttributeCondition
$creadsPrec :: Int -> ReadS DocumentAttributeCondition
Prelude.Read, Int -> DocumentAttributeCondition -> ShowS
[DocumentAttributeCondition] -> ShowS
DocumentAttributeCondition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DocumentAttributeCondition] -> ShowS
$cshowList :: [DocumentAttributeCondition] -> ShowS
show :: DocumentAttributeCondition -> String
$cshow :: DocumentAttributeCondition -> String
showsPrec :: Int -> DocumentAttributeCondition -> ShowS
$cshowsPrec :: Int -> DocumentAttributeCondition -> ShowS
Prelude.Show, forall x.
Rep DocumentAttributeCondition x -> DocumentAttributeCondition
forall x.
DocumentAttributeCondition -> Rep DocumentAttributeCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DocumentAttributeCondition x -> DocumentAttributeCondition
$cfrom :: forall x.
DocumentAttributeCondition -> Rep DocumentAttributeCondition x
Prelude.Generic)

-- |
-- Create a value of 'DocumentAttributeCondition' 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:
--
-- 'conditionOnValue', 'documentAttributeCondition_conditionOnValue' - The value used by the operator.
--
-- For example, you can specify the value \'financial\' for strings in the
-- \'Source_URI\' field that partially match or contain this value.
--
-- 'conditionDocumentAttributeKey', 'documentAttributeCondition_conditionDocumentAttributeKey' - The identifier of the document attribute used for the condition.
--
-- For example, \'Source_URI\' could be an identifier for the attribute or
-- metadata field that contains source URIs associated with the documents.
--
-- Amazon Kendra currently does not support @_document_body@ as an
-- attribute key used for the condition.
--
-- 'operator', 'documentAttributeCondition_operator' - The condition operator.
--
-- For example, you can use \'Contains\' to partially match a string.
newDocumentAttributeCondition ::
  -- | 'conditionDocumentAttributeKey'
  Prelude.Text ->
  -- | 'operator'
  ConditionOperator ->
  DocumentAttributeCondition
newDocumentAttributeCondition :: Text -> ConditionOperator -> DocumentAttributeCondition
newDocumentAttributeCondition
  Text
pConditionDocumentAttributeKey_
  ConditionOperator
pOperator_ =
    DocumentAttributeCondition'
      { $sel:conditionOnValue:DocumentAttributeCondition' :: Maybe DocumentAttributeValue
conditionOnValue =
          forall a. Maybe a
Prelude.Nothing,
        $sel:conditionDocumentAttributeKey:DocumentAttributeCondition' :: Text
conditionDocumentAttributeKey =
          Text
pConditionDocumentAttributeKey_,
        $sel:operator:DocumentAttributeCondition' :: ConditionOperator
operator = ConditionOperator
pOperator_
      }

-- | The value used by the operator.
--
-- For example, you can specify the value \'financial\' for strings in the
-- \'Source_URI\' field that partially match or contain this value.
documentAttributeCondition_conditionOnValue :: Lens.Lens' DocumentAttributeCondition (Prelude.Maybe DocumentAttributeValue)
documentAttributeCondition_conditionOnValue :: Lens' DocumentAttributeCondition (Maybe DocumentAttributeValue)
documentAttributeCondition_conditionOnValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DocumentAttributeCondition' {Maybe DocumentAttributeValue
conditionOnValue :: Maybe DocumentAttributeValue
$sel:conditionOnValue:DocumentAttributeCondition' :: DocumentAttributeCondition -> Maybe DocumentAttributeValue
conditionOnValue} -> Maybe DocumentAttributeValue
conditionOnValue) (\s :: DocumentAttributeCondition
s@DocumentAttributeCondition' {} Maybe DocumentAttributeValue
a -> DocumentAttributeCondition
s {$sel:conditionOnValue:DocumentAttributeCondition' :: Maybe DocumentAttributeValue
conditionOnValue = Maybe DocumentAttributeValue
a} :: DocumentAttributeCondition)

-- | The identifier of the document attribute used for the condition.
--
-- For example, \'Source_URI\' could be an identifier for the attribute or
-- metadata field that contains source URIs associated with the documents.
--
-- Amazon Kendra currently does not support @_document_body@ as an
-- attribute key used for the condition.
documentAttributeCondition_conditionDocumentAttributeKey :: Lens.Lens' DocumentAttributeCondition Prelude.Text
documentAttributeCondition_conditionDocumentAttributeKey :: Lens' DocumentAttributeCondition Text
documentAttributeCondition_conditionDocumentAttributeKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DocumentAttributeCondition' {Text
conditionDocumentAttributeKey :: Text
$sel:conditionDocumentAttributeKey:DocumentAttributeCondition' :: DocumentAttributeCondition -> Text
conditionDocumentAttributeKey} -> Text
conditionDocumentAttributeKey) (\s :: DocumentAttributeCondition
s@DocumentAttributeCondition' {} Text
a -> DocumentAttributeCondition
s {$sel:conditionDocumentAttributeKey:DocumentAttributeCondition' :: Text
conditionDocumentAttributeKey = Text
a} :: DocumentAttributeCondition)

-- | The condition operator.
--
-- For example, you can use \'Contains\' to partially match a string.
documentAttributeCondition_operator :: Lens.Lens' DocumentAttributeCondition ConditionOperator
documentAttributeCondition_operator :: Lens' DocumentAttributeCondition ConditionOperator
documentAttributeCondition_operator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DocumentAttributeCondition' {ConditionOperator
operator :: ConditionOperator
$sel:operator:DocumentAttributeCondition' :: DocumentAttributeCondition -> ConditionOperator
operator} -> ConditionOperator
operator) (\s :: DocumentAttributeCondition
s@DocumentAttributeCondition' {} ConditionOperator
a -> DocumentAttributeCondition
s {$sel:operator:DocumentAttributeCondition' :: ConditionOperator
operator = ConditionOperator
a} :: DocumentAttributeCondition)

instance Data.FromJSON DocumentAttributeCondition where
  parseJSON :: Value -> Parser DocumentAttributeCondition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DocumentAttributeCondition"
      ( \Object
x ->
          Maybe DocumentAttributeValue
-> Text -> ConditionOperator -> DocumentAttributeCondition
DocumentAttributeCondition'
            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
"ConditionOnValue")
            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
"ConditionDocumentAttributeKey")
            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
"Operator")
      )

instance Prelude.Hashable DocumentAttributeCondition where
  hashWithSalt :: Int -> DocumentAttributeCondition -> Int
hashWithSalt Int
_salt DocumentAttributeCondition' {Maybe DocumentAttributeValue
Text
ConditionOperator
operator :: ConditionOperator
conditionDocumentAttributeKey :: Text
conditionOnValue :: Maybe DocumentAttributeValue
$sel:operator:DocumentAttributeCondition' :: DocumentAttributeCondition -> ConditionOperator
$sel:conditionDocumentAttributeKey:DocumentAttributeCondition' :: DocumentAttributeCondition -> Text
$sel:conditionOnValue:DocumentAttributeCondition' :: DocumentAttributeCondition -> Maybe DocumentAttributeValue
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DocumentAttributeValue
conditionOnValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
conditionDocumentAttributeKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ConditionOperator
operator

instance Prelude.NFData DocumentAttributeCondition where
  rnf :: DocumentAttributeCondition -> ()
rnf DocumentAttributeCondition' {Maybe DocumentAttributeValue
Text
ConditionOperator
operator :: ConditionOperator
conditionDocumentAttributeKey :: Text
conditionOnValue :: Maybe DocumentAttributeValue
$sel:operator:DocumentAttributeCondition' :: DocumentAttributeCondition -> ConditionOperator
$sel:conditionDocumentAttributeKey:DocumentAttributeCondition' :: DocumentAttributeCondition -> Text
$sel:conditionOnValue:DocumentAttributeCondition' :: DocumentAttributeCondition -> Maybe DocumentAttributeValue
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe DocumentAttributeValue
conditionOnValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
conditionDocumentAttributeKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ConditionOperator
operator

instance Data.ToJSON DocumentAttributeCondition where
  toJSON :: DocumentAttributeCondition -> Value
toJSON DocumentAttributeCondition' {Maybe DocumentAttributeValue
Text
ConditionOperator
operator :: ConditionOperator
conditionDocumentAttributeKey :: Text
conditionOnValue :: Maybe DocumentAttributeValue
$sel:operator:DocumentAttributeCondition' :: DocumentAttributeCondition -> ConditionOperator
$sel:conditionDocumentAttributeKey:DocumentAttributeCondition' :: DocumentAttributeCondition -> Text
$sel:conditionOnValue:DocumentAttributeCondition' :: DocumentAttributeCondition -> Maybe DocumentAttributeValue
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ConditionOnValue" 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 DocumentAttributeValue
conditionOnValue,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"ConditionDocumentAttributeKey"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
conditionDocumentAttributeKey
              ),
            forall a. a -> Maybe a
Prelude.Just (Key
"Operator" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ConditionOperator
operator)
          ]
      )