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

-- | An excerpt from a table within a document. The table excerpt displays up
-- to five columns and three rows, depending on how many table cells are
-- relevant to the query and how many columns are available in the original
-- table. The top most relevant cell is displayed in the table excerpt,
-- along with the next most relevant cells.
--
-- /See:/ 'newTableExcerpt' smart constructor.
data TableExcerpt = TableExcerpt'
  { -- | A list of rows in the table excerpt.
    TableExcerpt -> Maybe [TableRow]
rows :: Prelude.Maybe [TableRow],
    -- | A count of the number of rows in the original table within the document.
    TableExcerpt -> Maybe Int
totalNumberOfRows :: Prelude.Maybe Prelude.Int
  }
  deriving (TableExcerpt -> TableExcerpt -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TableExcerpt -> TableExcerpt -> Bool
$c/= :: TableExcerpt -> TableExcerpt -> Bool
== :: TableExcerpt -> TableExcerpt -> Bool
$c== :: TableExcerpt -> TableExcerpt -> Bool
Prelude.Eq, ReadPrec [TableExcerpt]
ReadPrec TableExcerpt
Int -> ReadS TableExcerpt
ReadS [TableExcerpt]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TableExcerpt]
$creadListPrec :: ReadPrec [TableExcerpt]
readPrec :: ReadPrec TableExcerpt
$creadPrec :: ReadPrec TableExcerpt
readList :: ReadS [TableExcerpt]
$creadList :: ReadS [TableExcerpt]
readsPrec :: Int -> ReadS TableExcerpt
$creadsPrec :: Int -> ReadS TableExcerpt
Prelude.Read, Int -> TableExcerpt -> ShowS
[TableExcerpt] -> ShowS
TableExcerpt -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TableExcerpt] -> ShowS
$cshowList :: [TableExcerpt] -> ShowS
show :: TableExcerpt -> String
$cshow :: TableExcerpt -> String
showsPrec :: Int -> TableExcerpt -> ShowS
$cshowsPrec :: Int -> TableExcerpt -> ShowS
Prelude.Show, forall x. Rep TableExcerpt x -> TableExcerpt
forall x. TableExcerpt -> Rep TableExcerpt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TableExcerpt x -> TableExcerpt
$cfrom :: forall x. TableExcerpt -> Rep TableExcerpt x
Prelude.Generic)

-- |
-- Create a value of 'TableExcerpt' 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:
--
-- 'rows', 'tableExcerpt_rows' - A list of rows in the table excerpt.
--
-- 'totalNumberOfRows', 'tableExcerpt_totalNumberOfRows' - A count of the number of rows in the original table within the document.
newTableExcerpt ::
  TableExcerpt
newTableExcerpt :: TableExcerpt
newTableExcerpt =
  TableExcerpt'
    { $sel:rows:TableExcerpt' :: Maybe [TableRow]
rows = forall a. Maybe a
Prelude.Nothing,
      $sel:totalNumberOfRows:TableExcerpt' :: Maybe Int
totalNumberOfRows = forall a. Maybe a
Prelude.Nothing
    }

-- | A list of rows in the table excerpt.
tableExcerpt_rows :: Lens.Lens' TableExcerpt (Prelude.Maybe [TableRow])
tableExcerpt_rows :: Lens' TableExcerpt (Maybe [TableRow])
tableExcerpt_rows = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TableExcerpt' {Maybe [TableRow]
rows :: Maybe [TableRow]
$sel:rows:TableExcerpt' :: TableExcerpt -> Maybe [TableRow]
rows} -> Maybe [TableRow]
rows) (\s :: TableExcerpt
s@TableExcerpt' {} Maybe [TableRow]
a -> TableExcerpt
s {$sel:rows:TableExcerpt' :: Maybe [TableRow]
rows = Maybe [TableRow]
a} :: TableExcerpt) 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

-- | A count of the number of rows in the original table within the document.
tableExcerpt_totalNumberOfRows :: Lens.Lens' TableExcerpt (Prelude.Maybe Prelude.Int)
tableExcerpt_totalNumberOfRows :: Lens' TableExcerpt (Maybe Int)
tableExcerpt_totalNumberOfRows = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TableExcerpt' {Maybe Int
totalNumberOfRows :: Maybe Int
$sel:totalNumberOfRows:TableExcerpt' :: TableExcerpt -> Maybe Int
totalNumberOfRows} -> Maybe Int
totalNumberOfRows) (\s :: TableExcerpt
s@TableExcerpt' {} Maybe Int
a -> TableExcerpt
s {$sel:totalNumberOfRows:TableExcerpt' :: Maybe Int
totalNumberOfRows = Maybe Int
a} :: TableExcerpt)

instance Data.FromJSON TableExcerpt where
  parseJSON :: Value -> Parser TableExcerpt
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TableExcerpt"
      ( \Object
x ->
          Maybe [TableRow] -> Maybe Int -> TableExcerpt
TableExcerpt'
            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
"Rows" 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
"TotalNumberOfRows")
      )

instance Prelude.Hashable TableExcerpt where
  hashWithSalt :: Int -> TableExcerpt -> Int
hashWithSalt Int
_salt TableExcerpt' {Maybe Int
Maybe [TableRow]
totalNumberOfRows :: Maybe Int
rows :: Maybe [TableRow]
$sel:totalNumberOfRows:TableExcerpt' :: TableExcerpt -> Maybe Int
$sel:rows:TableExcerpt' :: TableExcerpt -> Maybe [TableRow]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [TableRow]
rows
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
totalNumberOfRows

instance Prelude.NFData TableExcerpt where
  rnf :: TableExcerpt -> ()
rnf TableExcerpt' {Maybe Int
Maybe [TableRow]
totalNumberOfRows :: Maybe Int
rows :: Maybe [TableRow]
$sel:totalNumberOfRows:TableExcerpt' :: TableExcerpt -> Maybe Int
$sel:rows:TableExcerpt' :: TableExcerpt -> Maybe [TableRow]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [TableRow]
rows
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
totalNumberOfRows