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

-- | A corrected misspelled word in a query.
--
-- /See:/ 'newCorrection' smart constructor.
data Correction = Correction'
  { -- | The zero-based location in the response string or text where the
    -- corrected word starts.
    Correction -> Maybe Int
beginOffset :: Prelude.Maybe Prelude.Int,
    -- | The string or text of a corrected misspelled word in a query.
    Correction -> Maybe Text
correctedTerm :: Prelude.Maybe Prelude.Text,
    -- | The zero-based location in the response string or text where the
    -- corrected word ends.
    Correction -> Maybe Int
endOffset :: Prelude.Maybe Prelude.Int,
    -- | The string or text of a misspelled word in a query.
    Correction -> Maybe Text
term :: Prelude.Maybe Prelude.Text
  }
  deriving (Correction -> Correction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Correction -> Correction -> Bool
$c/= :: Correction -> Correction -> Bool
== :: Correction -> Correction -> Bool
$c== :: Correction -> Correction -> Bool
Prelude.Eq, ReadPrec [Correction]
ReadPrec Correction
Int -> ReadS Correction
ReadS [Correction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Correction]
$creadListPrec :: ReadPrec [Correction]
readPrec :: ReadPrec Correction
$creadPrec :: ReadPrec Correction
readList :: ReadS [Correction]
$creadList :: ReadS [Correction]
readsPrec :: Int -> ReadS Correction
$creadsPrec :: Int -> ReadS Correction
Prelude.Read, Int -> Correction -> ShowS
[Correction] -> ShowS
Correction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Correction] -> ShowS
$cshowList :: [Correction] -> ShowS
show :: Correction -> String
$cshow :: Correction -> String
showsPrec :: Int -> Correction -> ShowS
$cshowsPrec :: Int -> Correction -> ShowS
Prelude.Show, forall x. Rep Correction x -> Correction
forall x. Correction -> Rep Correction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Correction x -> Correction
$cfrom :: forall x. Correction -> Rep Correction x
Prelude.Generic)

-- |
-- Create a value of 'Correction' 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:
--
-- 'beginOffset', 'correction_beginOffset' - The zero-based location in the response string or text where the
-- corrected word starts.
--
-- 'correctedTerm', 'correction_correctedTerm' - The string or text of a corrected misspelled word in a query.
--
-- 'endOffset', 'correction_endOffset' - The zero-based location in the response string or text where the
-- corrected word ends.
--
-- 'term', 'correction_term' - The string or text of a misspelled word in a query.
newCorrection ::
  Correction
newCorrection :: Correction
newCorrection =
  Correction'
    { $sel:beginOffset:Correction' :: Maybe Int
beginOffset = forall a. Maybe a
Prelude.Nothing,
      $sel:correctedTerm:Correction' :: Maybe Text
correctedTerm = forall a. Maybe a
Prelude.Nothing,
      $sel:endOffset:Correction' :: Maybe Int
endOffset = forall a. Maybe a
Prelude.Nothing,
      $sel:term:Correction' :: Maybe Text
term = forall a. Maybe a
Prelude.Nothing
    }

-- | The zero-based location in the response string or text where the
-- corrected word starts.
correction_beginOffset :: Lens.Lens' Correction (Prelude.Maybe Prelude.Int)
correction_beginOffset :: Lens' Correction (Maybe Int)
correction_beginOffset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Correction' {Maybe Int
beginOffset :: Maybe Int
$sel:beginOffset:Correction' :: Correction -> Maybe Int
beginOffset} -> Maybe Int
beginOffset) (\s :: Correction
s@Correction' {} Maybe Int
a -> Correction
s {$sel:beginOffset:Correction' :: Maybe Int
beginOffset = Maybe Int
a} :: Correction)

-- | The string or text of a corrected misspelled word in a query.
correction_correctedTerm :: Lens.Lens' Correction (Prelude.Maybe Prelude.Text)
correction_correctedTerm :: Lens' Correction (Maybe Text)
correction_correctedTerm = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Correction' {Maybe Text
correctedTerm :: Maybe Text
$sel:correctedTerm:Correction' :: Correction -> Maybe Text
correctedTerm} -> Maybe Text
correctedTerm) (\s :: Correction
s@Correction' {} Maybe Text
a -> Correction
s {$sel:correctedTerm:Correction' :: Maybe Text
correctedTerm = Maybe Text
a} :: Correction)

-- | The zero-based location in the response string or text where the
-- corrected word ends.
correction_endOffset :: Lens.Lens' Correction (Prelude.Maybe Prelude.Int)
correction_endOffset :: Lens' Correction (Maybe Int)
correction_endOffset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Correction' {Maybe Int
endOffset :: Maybe Int
$sel:endOffset:Correction' :: Correction -> Maybe Int
endOffset} -> Maybe Int
endOffset) (\s :: Correction
s@Correction' {} Maybe Int
a -> Correction
s {$sel:endOffset:Correction' :: Maybe Int
endOffset = Maybe Int
a} :: Correction)

-- | The string or text of a misspelled word in a query.
correction_term :: Lens.Lens' Correction (Prelude.Maybe Prelude.Text)
correction_term :: Lens' Correction (Maybe Text)
correction_term = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Correction' {Maybe Text
term :: Maybe Text
$sel:term:Correction' :: Correction -> Maybe Text
term} -> Maybe Text
term) (\s :: Correction
s@Correction' {} Maybe Text
a -> Correction
s {$sel:term:Correction' :: Maybe Text
term = Maybe Text
a} :: Correction)

instance Data.FromJSON Correction where
  parseJSON :: Value -> Parser Correction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Correction"
      ( \Object
x ->
          Maybe Int -> Maybe Text -> Maybe Int -> Maybe Text -> Correction
Correction'
            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
"BeginOffset")
            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
"CorrectedTerm")
            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
"EndOffset")
            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
"Term")
      )

instance Prelude.Hashable Correction where
  hashWithSalt :: Int -> Correction -> Int
hashWithSalt Int
_salt Correction' {Maybe Int
Maybe Text
term :: Maybe Text
endOffset :: Maybe Int
correctedTerm :: Maybe Text
beginOffset :: Maybe Int
$sel:term:Correction' :: Correction -> Maybe Text
$sel:endOffset:Correction' :: Correction -> Maybe Int
$sel:correctedTerm:Correction' :: Correction -> Maybe Text
$sel:beginOffset:Correction' :: Correction -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
beginOffset
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
correctedTerm
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
endOffset
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
term

instance Prelude.NFData Correction where
  rnf :: Correction -> ()
rnf Correction' {Maybe Int
Maybe Text
term :: Maybe Text
endOffset :: Maybe Int
correctedTerm :: Maybe Text
beginOffset :: Maybe Int
$sel:term:Correction' :: Correction -> Maybe Text
$sel:endOffset:Correction' :: Correction -> Maybe Int
$sel:correctedTerm:Correction' :: Correction -> Maybe Text
$sel:beginOffset:Correction' :: Correction -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
beginOffset
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
correctedTerm
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
endOffset
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
term