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

-- | Provides text and information about where to highlight the text.
--
-- /See:/ 'newTextWithHighlights' smart constructor.
data TextWithHighlights = TextWithHighlights'
  { -- | The beginning and end of the text that should be highlighted.
    TextWithHighlights -> Maybe [Highlight]
highlights :: Prelude.Maybe [Highlight],
    -- | The text to display to the user.
    TextWithHighlights -> Maybe Text
text :: Prelude.Maybe Prelude.Text
  }
  deriving (TextWithHighlights -> TextWithHighlights -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TextWithHighlights -> TextWithHighlights -> Bool
$c/= :: TextWithHighlights -> TextWithHighlights -> Bool
== :: TextWithHighlights -> TextWithHighlights -> Bool
$c== :: TextWithHighlights -> TextWithHighlights -> Bool
Prelude.Eq, ReadPrec [TextWithHighlights]
ReadPrec TextWithHighlights
Int -> ReadS TextWithHighlights
ReadS [TextWithHighlights]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TextWithHighlights]
$creadListPrec :: ReadPrec [TextWithHighlights]
readPrec :: ReadPrec TextWithHighlights
$creadPrec :: ReadPrec TextWithHighlights
readList :: ReadS [TextWithHighlights]
$creadList :: ReadS [TextWithHighlights]
readsPrec :: Int -> ReadS TextWithHighlights
$creadsPrec :: Int -> ReadS TextWithHighlights
Prelude.Read, Int -> TextWithHighlights -> ShowS
[TextWithHighlights] -> ShowS
TextWithHighlights -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TextWithHighlights] -> ShowS
$cshowList :: [TextWithHighlights] -> ShowS
show :: TextWithHighlights -> String
$cshow :: TextWithHighlights -> String
showsPrec :: Int -> TextWithHighlights -> ShowS
$cshowsPrec :: Int -> TextWithHighlights -> ShowS
Prelude.Show, forall x. Rep TextWithHighlights x -> TextWithHighlights
forall x. TextWithHighlights -> Rep TextWithHighlights x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TextWithHighlights x -> TextWithHighlights
$cfrom :: forall x. TextWithHighlights -> Rep TextWithHighlights x
Prelude.Generic)

-- |
-- Create a value of 'TextWithHighlights' 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:
--
-- 'highlights', 'textWithHighlights_highlights' - The beginning and end of the text that should be highlighted.
--
-- 'text', 'textWithHighlights_text' - The text to display to the user.
newTextWithHighlights ::
  TextWithHighlights
newTextWithHighlights :: TextWithHighlights
newTextWithHighlights =
  TextWithHighlights'
    { $sel:highlights:TextWithHighlights' :: Maybe [Highlight]
highlights = forall a. Maybe a
Prelude.Nothing,
      $sel:text:TextWithHighlights' :: Maybe Text
text = forall a. Maybe a
Prelude.Nothing
    }

-- | The beginning and end of the text that should be highlighted.
textWithHighlights_highlights :: Lens.Lens' TextWithHighlights (Prelude.Maybe [Highlight])
textWithHighlights_highlights :: Lens' TextWithHighlights (Maybe [Highlight])
textWithHighlights_highlights = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TextWithHighlights' {Maybe [Highlight]
highlights :: Maybe [Highlight]
$sel:highlights:TextWithHighlights' :: TextWithHighlights -> Maybe [Highlight]
highlights} -> Maybe [Highlight]
highlights) (\s :: TextWithHighlights
s@TextWithHighlights' {} Maybe [Highlight]
a -> TextWithHighlights
s {$sel:highlights:TextWithHighlights' :: Maybe [Highlight]
highlights = Maybe [Highlight]
a} :: TextWithHighlights) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The text to display to the user.
textWithHighlights_text :: Lens.Lens' TextWithHighlights (Prelude.Maybe Prelude.Text)
textWithHighlights_text :: Lens' TextWithHighlights (Maybe Text)
textWithHighlights_text = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TextWithHighlights' {Maybe Text
text :: Maybe Text
$sel:text:TextWithHighlights' :: TextWithHighlights -> Maybe Text
text} -> Maybe Text
text) (\s :: TextWithHighlights
s@TextWithHighlights' {} Maybe Text
a -> TextWithHighlights
s {$sel:text:TextWithHighlights' :: Maybe Text
text = Maybe Text
a} :: TextWithHighlights)

instance Data.FromJSON TextWithHighlights where
  parseJSON :: Value -> Parser TextWithHighlights
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TextWithHighlights"
      ( \Object
x ->
          Maybe [Highlight] -> Maybe Text -> TextWithHighlights
TextWithHighlights'
            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
"Highlights" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Text")
      )

instance Prelude.Hashable TextWithHighlights where
  hashWithSalt :: Int -> TextWithHighlights -> Int
hashWithSalt Int
_salt TextWithHighlights' {Maybe [Highlight]
Maybe Text
text :: Maybe Text
highlights :: Maybe [Highlight]
$sel:text:TextWithHighlights' :: TextWithHighlights -> Maybe Text
$sel:highlights:TextWithHighlights' :: TextWithHighlights -> Maybe [Highlight]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Highlight]
highlights
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
text

instance Prelude.NFData TextWithHighlights where
  rnf :: TextWithHighlights -> ()
rnf TextWithHighlights' {Maybe [Highlight]
Maybe Text
text :: Maybe Text
highlights :: Maybe [Highlight]
$sel:text:TextWithHighlights' :: TextWithHighlights -> Maybe Text
$sel:highlights:TextWithHighlights' :: TextWithHighlights -> Maybe [Highlight]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Highlight]
highlights
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
text