{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- 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.Lens as Lens
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,
    -- | 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,
    -- | The total number of documents that match the search request.
    Hits -> Maybe Integer
found :: Prelude.Maybe Prelude.Integer
  }
  deriving (Hits -> Hits -> Bool
(Hits -> Hits -> Bool) -> (Hits -> Hits -> Bool) -> Eq Hits
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]
(Int -> ReadS Hits)
-> ReadS [Hits] -> ReadPrec Hits -> ReadPrec [Hits] -> Read 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
(Int -> Hits -> ShowS)
-> (Hits -> String) -> ([Hits] -> ShowS) -> Show Hits
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. Hits -> Rep Hits x)
-> (forall x. Rep Hits x -> Hits) -> Generic Hits
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.
--
-- 'hit', 'hits_hit' - A document that matches the search request.
--
-- 'start', 'hits_start' - The index of the first matching document.
--
-- 'found', 'hits_found' - The total number of documents that match the search request.
newHits ::
  Hits
newHits :: Hits
newHits =
  Hits' :: Maybe Text -> Maybe [Hit] -> Maybe Integer -> Maybe Integer -> Hits
Hits'
    { $sel:cursor:Hits' :: Maybe Text
cursor = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:hit:Hits' :: Maybe [Hit]
hit = Maybe [Hit]
forall a. Maybe a
Prelude.Nothing,
      $sel:start:Hits' :: Maybe Integer
start = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:found:Hits' :: Maybe Integer
found = Maybe Integer
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 :: (Maybe Text -> f (Maybe Text)) -> Hits -> f Hits
hits_cursor = (Hits -> Maybe Text)
-> (Hits -> Maybe Text -> Hits)
-> Lens Hits Hits (Maybe Text) (Maybe Text)
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)

-- | A document that matches the search request.
hits_hit :: Lens.Lens' Hits (Prelude.Maybe [Hit])
hits_hit :: (Maybe [Hit] -> f (Maybe [Hit])) -> Hits -> f Hits
hits_hit = (Hits -> Maybe [Hit])
-> (Hits -> Maybe [Hit] -> Hits)
-> Lens Hits Hits (Maybe [Hit]) (Maybe [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) ((Maybe [Hit] -> f (Maybe [Hit])) -> Hits -> f Hits)
-> ((Maybe [Hit] -> f (Maybe [Hit]))
    -> Maybe [Hit] -> f (Maybe [Hit]))
-> (Maybe [Hit] -> f (Maybe [Hit]))
-> Hits
-> f Hits
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Hit] [Hit] [Hit] [Hit]
-> Iso (Maybe [Hit]) (Maybe [Hit]) (Maybe [Hit]) (Maybe [Hit])
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 AnIso [Hit] [Hit] [Hit] [Hit]
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 :: (Maybe Integer -> f (Maybe Integer)) -> Hits -> f Hits
hits_start = (Hits -> Maybe Integer)
-> (Hits -> Maybe Integer -> Hits)
-> Lens Hits Hits (Maybe Integer) (Maybe Integer)
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)

-- | The total number of documents that match the search request.
hits_found :: Lens.Lens' Hits (Prelude.Maybe Prelude.Integer)
hits_found :: (Maybe Integer -> f (Maybe Integer)) -> Hits -> f Hits
hits_found = (Hits -> Maybe Integer)
-> (Hits -> Maybe Integer -> Hits)
-> Lens Hits Hits (Maybe Integer) (Maybe Integer)
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)

instance Core.FromJSON Hits where
  parseJSON :: Value -> Parser Hits
parseJSON =
    String -> (Object -> Parser Hits) -> Value -> Parser Hits
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Hits"
      ( \Object
x ->
          Maybe Text -> Maybe [Hit] -> Maybe Integer -> Maybe Integer -> Hits
Hits'
            (Maybe Text
 -> Maybe [Hit] -> Maybe Integer -> Maybe Integer -> Hits)
-> Parser (Maybe Text)
-> Parser (Maybe [Hit] -> Maybe Integer -> Maybe Integer -> Hits)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"cursor")
            Parser (Maybe [Hit] -> Maybe Integer -> Maybe Integer -> Hits)
-> Parser (Maybe [Hit])
-> Parser (Maybe Integer -> Maybe Integer -> Hits)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Hit]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"hit" Parser (Maybe (Maybe [Hit])) -> Maybe [Hit] -> Parser (Maybe [Hit])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Hit]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Integer -> Maybe Integer -> Hits)
-> Parser (Maybe Integer) -> Parser (Maybe Integer -> Hits)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"start")
            Parser (Maybe Integer -> Hits)
-> Parser (Maybe Integer) -> Parser Hits
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"found")
      )

instance Prelude.Hashable Hits

instance Prelude.NFData Hits