{-# 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.CloudSearchDomains.Types.Hits
-- 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.CloudSearchDomains.Types.Hits where

import Amazonka.CloudSearchDomains.Types.Hit
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

-- | The collection of documents that match the search request.
--
-- /See:/ 'newHits' smart constructor.
data Hits = Hits'
  { -- | A cursor that can be used to retrieve the next set of matching documents
    -- when you want to page through a large result set.
    Hits -> Maybe Text
cursor :: Prelude.Maybe Prelude.Text,
    -- | The total number of documents that match the search request.
    Hits -> Maybe Integer
found :: Prelude.Maybe Prelude.Integer,
    -- | A document that matches the search request.
    Hits -> Maybe [Hit]
hit :: Prelude.Maybe [Hit],
    -- | The index of the first matching document.
    Hits -> Maybe Integer
start :: Prelude.Maybe Prelude.Integer
  }
  deriving (Hits -> Hits -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Hits -> Hits -> Bool
$c/= :: Hits -> Hits -> Bool
== :: Hits -> Hits -> Bool
$c== :: Hits -> Hits -> Bool
Prelude.Eq, ReadPrec [Hits]
ReadPrec Hits
Int -> ReadS Hits
ReadS [Hits]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Hits]
$creadListPrec :: ReadPrec [Hits]
readPrec :: ReadPrec Hits
$creadPrec :: ReadPrec Hits
readList :: ReadS [Hits]
$creadList :: ReadS [Hits]
readsPrec :: Int -> ReadS Hits
$creadsPrec :: Int -> ReadS Hits
Prelude.Read, Int -> Hits -> ShowS
[Hits] -> ShowS
Hits -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Hits] -> ShowS
$cshowList :: [Hits] -> ShowS
show :: Hits -> String
$cshow :: Hits -> String
showsPrec :: Int -> Hits -> ShowS
$cshowsPrec :: Int -> Hits -> ShowS
Prelude.Show, forall x. Rep Hits x -> Hits
forall x. Hits -> Rep Hits x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Hits x -> Hits
$cfrom :: forall x. Hits -> Rep Hits x
Prelude.Generic)

-- |
-- Create a value of 'Hits' 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:
--
-- 'cursor', 'hits_cursor' - A cursor that can be used to retrieve the next set of matching documents
-- when you want to page through a large result set.
--
-- 'found', 'hits_found' - The total number of documents that match the search request.
--
-- 'hit', 'hits_hit' - A document that matches the search request.
--
-- 'start', 'hits_start' - The index of the first matching document.
newHits ::
  Hits
newHits :: Hits
newHits =
  Hits'
    { $sel:cursor:Hits' :: Maybe Text
cursor = forall a. Maybe a
Prelude.Nothing,
      $sel:found:Hits' :: Maybe Integer
found = forall a. Maybe a
Prelude.Nothing,
      $sel:hit:Hits' :: Maybe [Hit]
hit = forall a. Maybe a
Prelude.Nothing,
      $sel:start:Hits' :: Maybe Integer
start = forall a. Maybe a
Prelude.Nothing
    }

-- | A cursor that can be used to retrieve the next set of matching documents
-- when you want to page through a large result set.
hits_cursor :: Lens.Lens' Hits (Prelude.Maybe Prelude.Text)
hits_cursor :: Lens' Hits (Maybe Text)
hits_cursor = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Hits' {Maybe Text
cursor :: Maybe Text
$sel:cursor:Hits' :: Hits -> Maybe Text
cursor} -> Maybe Text
cursor) (\s :: Hits
s@Hits' {} Maybe Text
a -> Hits
s {$sel:cursor:Hits' :: Maybe Text
cursor = Maybe Text
a} :: Hits)

-- | The total number of documents that match the search request.
hits_found :: Lens.Lens' Hits (Prelude.Maybe Prelude.Integer)
hits_found :: Lens' Hits (Maybe Integer)
hits_found = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Hits' {Maybe Integer
found :: Maybe Integer
$sel:found:Hits' :: Hits -> Maybe Integer
found} -> Maybe Integer
found) (\s :: Hits
s@Hits' {} Maybe Integer
a -> Hits
s {$sel:found:Hits' :: Maybe Integer
found = Maybe Integer
a} :: Hits)

-- | A document that matches the search request.
hits_hit :: Lens.Lens' Hits (Prelude.Maybe [Hit])
hits_hit :: Lens' Hits (Maybe [Hit])
hits_hit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Hits' {Maybe [Hit]
hit :: Maybe [Hit]
$sel:hit:Hits' :: Hits -> Maybe [Hit]
hit} -> Maybe [Hit]
hit) (\s :: Hits
s@Hits' {} Maybe [Hit]
a -> Hits
s {$sel:hit:Hits' :: Maybe [Hit]
hit = Maybe [Hit]
a} :: Hits) 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 index of the first matching document.
hits_start :: Lens.Lens' Hits (Prelude.Maybe Prelude.Integer)
hits_start :: Lens' Hits (Maybe Integer)
hits_start = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Hits' {Maybe Integer
start :: Maybe Integer
$sel:start:Hits' :: Hits -> Maybe Integer
start} -> Maybe Integer
start) (\s :: Hits
s@Hits' {} Maybe Integer
a -> Hits
s {$sel:start:Hits' :: Maybe Integer
start = Maybe Integer
a} :: Hits)

instance Data.FromJSON Hits where
  parseJSON :: Value -> Parser Hits
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Hits"
      ( \Object
x ->
          Maybe Text -> Maybe Integer -> Maybe [Hit] -> Maybe Integer -> Hits
Hits'
            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
"cursor")
            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
"found")
            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
"hit" 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
"start")
      )

instance Prelude.Hashable Hits where
  hashWithSalt :: Int -> Hits -> Int
hashWithSalt Int
_salt Hits' {Maybe Integer
Maybe [Hit]
Maybe Text
start :: Maybe Integer
hit :: Maybe [Hit]
found :: Maybe Integer
cursor :: Maybe Text
$sel:start:Hits' :: Hits -> Maybe Integer
$sel:hit:Hits' :: Hits -> Maybe [Hit]
$sel:found:Hits' :: Hits -> Maybe Integer
$sel:cursor:Hits' :: Hits -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
cursor
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
found
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Hit]
hit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
start

instance Prelude.NFData Hits where
  rnf :: Hits -> ()
rnf Hits' {Maybe Integer
Maybe [Hit]
Maybe Text
start :: Maybe Integer
hit :: Maybe [Hit]
found :: Maybe Integer
cursor :: Maybe Text
$sel:start:Hits' :: Hits -> Maybe Integer
$sel:hit:Hits' :: Hits -> Maybe [Hit]
$sel:found:Hits' :: Hits -> Maybe Integer
$sel:cursor:Hits' :: Hits -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
cursor
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
found
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Hit]
hit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
start