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

-- | Provides information that you can use to highlight a search result so
-- that your users can quickly identify terms in the response.
--
-- /See:/ 'newHighlight' smart constructor.
data Highlight = Highlight'
  { -- | Indicates whether the response is the best response. True if this is the
    -- best response; otherwise, false.
    Highlight -> Maybe Bool
topAnswer :: Prelude.Maybe Prelude.Bool,
    -- | The highlight type.
    Highlight -> Maybe HighlightType
type' :: Prelude.Maybe HighlightType,
    -- | The zero-based location in the response string where the highlight
    -- starts.
    Highlight -> Int
beginOffset :: Prelude.Int,
    -- | The zero-based location in the response string where the highlight ends.
    Highlight -> Int
endOffset :: Prelude.Int
  }
  deriving (Highlight -> Highlight -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Highlight -> Highlight -> Bool
$c/= :: Highlight -> Highlight -> Bool
== :: Highlight -> Highlight -> Bool
$c== :: Highlight -> Highlight -> Bool
Prelude.Eq, ReadPrec [Highlight]
ReadPrec Highlight
Int -> ReadS Highlight
ReadS [Highlight]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Highlight]
$creadListPrec :: ReadPrec [Highlight]
readPrec :: ReadPrec Highlight
$creadPrec :: ReadPrec Highlight
readList :: ReadS [Highlight]
$creadList :: ReadS [Highlight]
readsPrec :: Int -> ReadS Highlight
$creadsPrec :: Int -> ReadS Highlight
Prelude.Read, Int -> Highlight -> ShowS
[Highlight] -> ShowS
Highlight -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Highlight] -> ShowS
$cshowList :: [Highlight] -> ShowS
show :: Highlight -> String
$cshow :: Highlight -> String
showsPrec :: Int -> Highlight -> ShowS
$cshowsPrec :: Int -> Highlight -> ShowS
Prelude.Show, forall x. Rep Highlight x -> Highlight
forall x. Highlight -> Rep Highlight x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Highlight x -> Highlight
$cfrom :: forall x. Highlight -> Rep Highlight x
Prelude.Generic)

-- |
-- Create a value of 'Highlight' 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:
--
-- 'topAnswer', 'highlight_topAnswer' - Indicates whether the response is the best response. True if this is the
-- best response; otherwise, false.
--
-- 'type'', 'highlight_type' - The highlight type.
--
-- 'beginOffset', 'highlight_beginOffset' - The zero-based location in the response string where the highlight
-- starts.
--
-- 'endOffset', 'highlight_endOffset' - The zero-based location in the response string where the highlight ends.
newHighlight ::
  -- | 'beginOffset'
  Prelude.Int ->
  -- | 'endOffset'
  Prelude.Int ->
  Highlight
newHighlight :: Int -> Int -> Highlight
newHighlight Int
pBeginOffset_ Int
pEndOffset_ =
  Highlight'
    { $sel:topAnswer:Highlight' :: Maybe Bool
topAnswer = forall a. Maybe a
Prelude.Nothing,
      $sel:type':Highlight' :: Maybe HighlightType
type' = forall a. Maybe a
Prelude.Nothing,
      $sel:beginOffset:Highlight' :: Int
beginOffset = Int
pBeginOffset_,
      $sel:endOffset:Highlight' :: Int
endOffset = Int
pEndOffset_
    }

-- | Indicates whether the response is the best response. True if this is the
-- best response; otherwise, false.
highlight_topAnswer :: Lens.Lens' Highlight (Prelude.Maybe Prelude.Bool)
highlight_topAnswer :: Lens' Highlight (Maybe Bool)
highlight_topAnswer = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Highlight' {Maybe Bool
topAnswer :: Maybe Bool
$sel:topAnswer:Highlight' :: Highlight -> Maybe Bool
topAnswer} -> Maybe Bool
topAnswer) (\s :: Highlight
s@Highlight' {} Maybe Bool
a -> Highlight
s {$sel:topAnswer:Highlight' :: Maybe Bool
topAnswer = Maybe Bool
a} :: Highlight)

-- | The highlight type.
highlight_type :: Lens.Lens' Highlight (Prelude.Maybe HighlightType)
highlight_type :: Lens' Highlight (Maybe HighlightType)
highlight_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Highlight' {Maybe HighlightType
type' :: Maybe HighlightType
$sel:type':Highlight' :: Highlight -> Maybe HighlightType
type'} -> Maybe HighlightType
type') (\s :: Highlight
s@Highlight' {} Maybe HighlightType
a -> Highlight
s {$sel:type':Highlight' :: Maybe HighlightType
type' = Maybe HighlightType
a} :: Highlight)

-- | The zero-based location in the response string where the highlight
-- starts.
highlight_beginOffset :: Lens.Lens' Highlight Prelude.Int
highlight_beginOffset :: Lens' Highlight Int
highlight_beginOffset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Highlight' {Int
beginOffset :: Int
$sel:beginOffset:Highlight' :: Highlight -> Int
beginOffset} -> Int
beginOffset) (\s :: Highlight
s@Highlight' {} Int
a -> Highlight
s {$sel:beginOffset:Highlight' :: Int
beginOffset = Int
a} :: Highlight)

-- | The zero-based location in the response string where the highlight ends.
highlight_endOffset :: Lens.Lens' Highlight Prelude.Int
highlight_endOffset :: Lens' Highlight Int
highlight_endOffset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Highlight' {Int
endOffset :: Int
$sel:endOffset:Highlight' :: Highlight -> Int
endOffset} -> Int
endOffset) (\s :: Highlight
s@Highlight' {} Int
a -> Highlight
s {$sel:endOffset:Highlight' :: Int
endOffset = Int
a} :: Highlight)

instance Data.FromJSON Highlight where
  parseJSON :: Value -> Parser Highlight
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Highlight"
      ( \Object
x ->
          Maybe Bool -> Maybe HighlightType -> Int -> Int -> Highlight
Highlight'
            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
"TopAnswer")
            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
"Type")
            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
"BeginOffset")
            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
"EndOffset")
      )

instance Prelude.Hashable Highlight where
  hashWithSalt :: Int -> Highlight -> Int
hashWithSalt Int
_salt Highlight' {Int
Maybe Bool
Maybe HighlightType
endOffset :: Int
beginOffset :: Int
type' :: Maybe HighlightType
topAnswer :: Maybe Bool
$sel:endOffset:Highlight' :: Highlight -> Int
$sel:beginOffset:Highlight' :: Highlight -> Int
$sel:type':Highlight' :: Highlight -> Maybe HighlightType
$sel:topAnswer:Highlight' :: Highlight -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
topAnswer
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe HighlightType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
beginOffset
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
endOffset

instance Prelude.NFData Highlight where
  rnf :: Highlight -> ()
rnf Highlight' {Int
Maybe Bool
Maybe HighlightType
endOffset :: Int
beginOffset :: Int
type' :: Maybe HighlightType
topAnswer :: Maybe Bool
$sel:endOffset:Highlight' :: Highlight -> Int
$sel:beginOffset:Highlight' :: Highlight -> Int
$sel:type':Highlight' :: Highlight -> Maybe HighlightType
$sel:topAnswer:Highlight' :: Highlight -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
topAnswer
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe HighlightType
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
beginOffset
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
endOffset