{-# 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.DataSourceToIndexFieldMapping
-- 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.DataSourceToIndexFieldMapping 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

-- | Maps a column or attribute in the data source to an index field. You
-- must first create the fields in the index using the @UpdateIndex@ API.
--
-- /See:/ 'newDataSourceToIndexFieldMapping' smart constructor.
data DataSourceToIndexFieldMapping = DataSourceToIndexFieldMapping'
  { -- | The type of data stored in the column or attribute.
    DataSourceToIndexFieldMapping -> Maybe Text
dateFieldFormat :: Prelude.Maybe Prelude.Text,
    -- | The name of the column or attribute in the data source.
    DataSourceToIndexFieldMapping -> Text
dataSourceFieldName :: Prelude.Text,
    -- | The name of the field in the index.
    DataSourceToIndexFieldMapping -> Text
indexFieldName :: Prelude.Text
  }
  deriving (DataSourceToIndexFieldMapping
-> DataSourceToIndexFieldMapping -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DataSourceToIndexFieldMapping
-> DataSourceToIndexFieldMapping -> Bool
$c/= :: DataSourceToIndexFieldMapping
-> DataSourceToIndexFieldMapping -> Bool
== :: DataSourceToIndexFieldMapping
-> DataSourceToIndexFieldMapping -> Bool
$c== :: DataSourceToIndexFieldMapping
-> DataSourceToIndexFieldMapping -> Bool
Prelude.Eq, ReadPrec [DataSourceToIndexFieldMapping]
ReadPrec DataSourceToIndexFieldMapping
Int -> ReadS DataSourceToIndexFieldMapping
ReadS [DataSourceToIndexFieldMapping]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DataSourceToIndexFieldMapping]
$creadListPrec :: ReadPrec [DataSourceToIndexFieldMapping]
readPrec :: ReadPrec DataSourceToIndexFieldMapping
$creadPrec :: ReadPrec DataSourceToIndexFieldMapping
readList :: ReadS [DataSourceToIndexFieldMapping]
$creadList :: ReadS [DataSourceToIndexFieldMapping]
readsPrec :: Int -> ReadS DataSourceToIndexFieldMapping
$creadsPrec :: Int -> ReadS DataSourceToIndexFieldMapping
Prelude.Read, Int -> DataSourceToIndexFieldMapping -> ShowS
[DataSourceToIndexFieldMapping] -> ShowS
DataSourceToIndexFieldMapping -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DataSourceToIndexFieldMapping] -> ShowS
$cshowList :: [DataSourceToIndexFieldMapping] -> ShowS
show :: DataSourceToIndexFieldMapping -> String
$cshow :: DataSourceToIndexFieldMapping -> String
showsPrec :: Int -> DataSourceToIndexFieldMapping -> ShowS
$cshowsPrec :: Int -> DataSourceToIndexFieldMapping -> ShowS
Prelude.Show, forall x.
Rep DataSourceToIndexFieldMapping x
-> DataSourceToIndexFieldMapping
forall x.
DataSourceToIndexFieldMapping
-> Rep DataSourceToIndexFieldMapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DataSourceToIndexFieldMapping x
-> DataSourceToIndexFieldMapping
$cfrom :: forall x.
DataSourceToIndexFieldMapping
-> Rep DataSourceToIndexFieldMapping x
Prelude.Generic)

-- |
-- Create a value of 'DataSourceToIndexFieldMapping' 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:
--
-- 'dateFieldFormat', 'dataSourceToIndexFieldMapping_dateFieldFormat' - The type of data stored in the column or attribute.
--
-- 'dataSourceFieldName', 'dataSourceToIndexFieldMapping_dataSourceFieldName' - The name of the column or attribute in the data source.
--
-- 'indexFieldName', 'dataSourceToIndexFieldMapping_indexFieldName' - The name of the field in the index.
newDataSourceToIndexFieldMapping ::
  -- | 'dataSourceFieldName'
  Prelude.Text ->
  -- | 'indexFieldName'
  Prelude.Text ->
  DataSourceToIndexFieldMapping
newDataSourceToIndexFieldMapping :: Text -> Text -> DataSourceToIndexFieldMapping
newDataSourceToIndexFieldMapping
  Text
pDataSourceFieldName_
  Text
pIndexFieldName_ =
    DataSourceToIndexFieldMapping'
      { $sel:dateFieldFormat:DataSourceToIndexFieldMapping' :: Maybe Text
dateFieldFormat =
          forall a. Maybe a
Prelude.Nothing,
        $sel:dataSourceFieldName:DataSourceToIndexFieldMapping' :: Text
dataSourceFieldName = Text
pDataSourceFieldName_,
        $sel:indexFieldName:DataSourceToIndexFieldMapping' :: Text
indexFieldName = Text
pIndexFieldName_
      }

-- | The type of data stored in the column or attribute.
dataSourceToIndexFieldMapping_dateFieldFormat :: Lens.Lens' DataSourceToIndexFieldMapping (Prelude.Maybe Prelude.Text)
dataSourceToIndexFieldMapping_dateFieldFormat :: Lens' DataSourceToIndexFieldMapping (Maybe Text)
dataSourceToIndexFieldMapping_dateFieldFormat = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataSourceToIndexFieldMapping' {Maybe Text
dateFieldFormat :: Maybe Text
$sel:dateFieldFormat:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Maybe Text
dateFieldFormat} -> Maybe Text
dateFieldFormat) (\s :: DataSourceToIndexFieldMapping
s@DataSourceToIndexFieldMapping' {} Maybe Text
a -> DataSourceToIndexFieldMapping
s {$sel:dateFieldFormat:DataSourceToIndexFieldMapping' :: Maybe Text
dateFieldFormat = Maybe Text
a} :: DataSourceToIndexFieldMapping)

-- | The name of the column or attribute in the data source.
dataSourceToIndexFieldMapping_dataSourceFieldName :: Lens.Lens' DataSourceToIndexFieldMapping Prelude.Text
dataSourceToIndexFieldMapping_dataSourceFieldName :: Lens' DataSourceToIndexFieldMapping Text
dataSourceToIndexFieldMapping_dataSourceFieldName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataSourceToIndexFieldMapping' {Text
dataSourceFieldName :: Text
$sel:dataSourceFieldName:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Text
dataSourceFieldName} -> Text
dataSourceFieldName) (\s :: DataSourceToIndexFieldMapping
s@DataSourceToIndexFieldMapping' {} Text
a -> DataSourceToIndexFieldMapping
s {$sel:dataSourceFieldName:DataSourceToIndexFieldMapping' :: Text
dataSourceFieldName = Text
a} :: DataSourceToIndexFieldMapping)

-- | The name of the field in the index.
dataSourceToIndexFieldMapping_indexFieldName :: Lens.Lens' DataSourceToIndexFieldMapping Prelude.Text
dataSourceToIndexFieldMapping_indexFieldName :: Lens' DataSourceToIndexFieldMapping Text
dataSourceToIndexFieldMapping_indexFieldName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataSourceToIndexFieldMapping' {Text
indexFieldName :: Text
$sel:indexFieldName:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Text
indexFieldName} -> Text
indexFieldName) (\s :: DataSourceToIndexFieldMapping
s@DataSourceToIndexFieldMapping' {} Text
a -> DataSourceToIndexFieldMapping
s {$sel:indexFieldName:DataSourceToIndexFieldMapping' :: Text
indexFieldName = Text
a} :: DataSourceToIndexFieldMapping)

instance Data.FromJSON DataSourceToIndexFieldMapping where
  parseJSON :: Value -> Parser DataSourceToIndexFieldMapping
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DataSourceToIndexFieldMapping"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> DataSourceToIndexFieldMapping
DataSourceToIndexFieldMapping'
            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
"DateFieldFormat")
            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
"DataSourceFieldName")
            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
"IndexFieldName")
      )

instance
  Prelude.Hashable
    DataSourceToIndexFieldMapping
  where
  hashWithSalt :: Int -> DataSourceToIndexFieldMapping -> Int
hashWithSalt Int
_salt DataSourceToIndexFieldMapping' {Maybe Text
Text
indexFieldName :: Text
dataSourceFieldName :: Text
dateFieldFormat :: Maybe Text
$sel:indexFieldName:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Text
$sel:dataSourceFieldName:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Text
$sel:dateFieldFormat:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
dateFieldFormat
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
dataSourceFieldName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
indexFieldName

instance Prelude.NFData DataSourceToIndexFieldMapping where
  rnf :: DataSourceToIndexFieldMapping -> ()
rnf DataSourceToIndexFieldMapping' {Maybe Text
Text
indexFieldName :: Text
dataSourceFieldName :: Text
dateFieldFormat :: Maybe Text
$sel:indexFieldName:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Text
$sel:dataSourceFieldName:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Text
$sel:dateFieldFormat:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
dateFieldFormat
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
dataSourceFieldName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
indexFieldName

instance Data.ToJSON DataSourceToIndexFieldMapping where
  toJSON :: DataSourceToIndexFieldMapping -> Value
toJSON DataSourceToIndexFieldMapping' {Maybe Text
Text
indexFieldName :: Text
dataSourceFieldName :: Text
dateFieldFormat :: Maybe Text
$sel:indexFieldName:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Text
$sel:dataSourceFieldName:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Text
$sel:dateFieldFormat:DataSourceToIndexFieldMapping' :: DataSourceToIndexFieldMapping -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DateFieldFormat" 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 Text
dateFieldFormat,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"DataSourceFieldName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
dataSourceFieldName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"IndexFieldName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
indexFieldName)
          ]
      )