{-# 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.SuggestModel
-- 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.SuggestModel where

import Amazonka.CloudSearchDomains.Types.SuggestionMatch
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Container for the suggestion information returned in a
-- @SuggestResponse@.
--
-- /See:/ 'newSuggestModel' smart constructor.
data SuggestModel = SuggestModel'
  { -- | The number of documents that were found to match the query string.
    SuggestModel -> Maybe Integer
found :: Prelude.Maybe Prelude.Integer,
    -- | The documents that match the query string.
    SuggestModel -> Maybe [SuggestionMatch]
suggestions :: Prelude.Maybe [SuggestionMatch],
    -- | The query string specified in the suggest request.
    SuggestModel -> Maybe Text
query :: Prelude.Maybe Prelude.Text
  }
  deriving (SuggestModel -> SuggestModel -> Bool
(SuggestModel -> SuggestModel -> Bool)
-> (SuggestModel -> SuggestModel -> Bool) -> Eq SuggestModel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SuggestModel -> SuggestModel -> Bool
$c/= :: SuggestModel -> SuggestModel -> Bool
== :: SuggestModel -> SuggestModel -> Bool
$c== :: SuggestModel -> SuggestModel -> Bool
Prelude.Eq, ReadPrec [SuggestModel]
ReadPrec SuggestModel
Int -> ReadS SuggestModel
ReadS [SuggestModel]
(Int -> ReadS SuggestModel)
-> ReadS [SuggestModel]
-> ReadPrec SuggestModel
-> ReadPrec [SuggestModel]
-> Read SuggestModel
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SuggestModel]
$creadListPrec :: ReadPrec [SuggestModel]
readPrec :: ReadPrec SuggestModel
$creadPrec :: ReadPrec SuggestModel
readList :: ReadS [SuggestModel]
$creadList :: ReadS [SuggestModel]
readsPrec :: Int -> ReadS SuggestModel
$creadsPrec :: Int -> ReadS SuggestModel
Prelude.Read, Int -> SuggestModel -> ShowS
[SuggestModel] -> ShowS
SuggestModel -> String
(Int -> SuggestModel -> ShowS)
-> (SuggestModel -> String)
-> ([SuggestModel] -> ShowS)
-> Show SuggestModel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SuggestModel] -> ShowS
$cshowList :: [SuggestModel] -> ShowS
show :: SuggestModel -> String
$cshow :: SuggestModel -> String
showsPrec :: Int -> SuggestModel -> ShowS
$cshowsPrec :: Int -> SuggestModel -> ShowS
Prelude.Show, (forall x. SuggestModel -> Rep SuggestModel x)
-> (forall x. Rep SuggestModel x -> SuggestModel)
-> Generic SuggestModel
forall x. Rep SuggestModel x -> SuggestModel
forall x. SuggestModel -> Rep SuggestModel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SuggestModel x -> SuggestModel
$cfrom :: forall x. SuggestModel -> Rep SuggestModel x
Prelude.Generic)

-- |
-- Create a value of 'SuggestModel' 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:
--
-- 'found', 'suggestModel_found' - The number of documents that were found to match the query string.
--
-- 'suggestions', 'suggestModel_suggestions' - The documents that match the query string.
--
-- 'query', 'suggestModel_query' - The query string specified in the suggest request.
newSuggestModel ::
  SuggestModel
newSuggestModel :: SuggestModel
newSuggestModel =
  SuggestModel' :: Maybe Integer
-> Maybe [SuggestionMatch] -> Maybe Text -> SuggestModel
SuggestModel'
    { $sel:found:SuggestModel' :: Maybe Integer
found = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:suggestions:SuggestModel' :: Maybe [SuggestionMatch]
suggestions = Maybe [SuggestionMatch]
forall a. Maybe a
Prelude.Nothing,
      $sel:query:SuggestModel' :: Maybe Text
query = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The number of documents that were found to match the query string.
suggestModel_found :: Lens.Lens' SuggestModel (Prelude.Maybe Prelude.Integer)
suggestModel_found :: (Maybe Integer -> f (Maybe Integer))
-> SuggestModel -> f SuggestModel
suggestModel_found = (SuggestModel -> Maybe Integer)
-> (SuggestModel -> Maybe Integer -> SuggestModel)
-> Lens SuggestModel SuggestModel (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SuggestModel' {Maybe Integer
found :: Maybe Integer
$sel:found:SuggestModel' :: SuggestModel -> Maybe Integer
found} -> Maybe Integer
found) (\s :: SuggestModel
s@SuggestModel' {} Maybe Integer
a -> SuggestModel
s {$sel:found:SuggestModel' :: Maybe Integer
found = Maybe Integer
a} :: SuggestModel)

-- | The documents that match the query string.
suggestModel_suggestions :: Lens.Lens' SuggestModel (Prelude.Maybe [SuggestionMatch])
suggestModel_suggestions :: (Maybe [SuggestionMatch] -> f (Maybe [SuggestionMatch]))
-> SuggestModel -> f SuggestModel
suggestModel_suggestions = (SuggestModel -> Maybe [SuggestionMatch])
-> (SuggestModel -> Maybe [SuggestionMatch] -> SuggestModel)
-> Lens
     SuggestModel
     SuggestModel
     (Maybe [SuggestionMatch])
     (Maybe [SuggestionMatch])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SuggestModel' {Maybe [SuggestionMatch]
suggestions :: Maybe [SuggestionMatch]
$sel:suggestions:SuggestModel' :: SuggestModel -> Maybe [SuggestionMatch]
suggestions} -> Maybe [SuggestionMatch]
suggestions) (\s :: SuggestModel
s@SuggestModel' {} Maybe [SuggestionMatch]
a -> SuggestModel
s {$sel:suggestions:SuggestModel' :: Maybe [SuggestionMatch]
suggestions = Maybe [SuggestionMatch]
a} :: SuggestModel) ((Maybe [SuggestionMatch] -> f (Maybe [SuggestionMatch]))
 -> SuggestModel -> f SuggestModel)
-> ((Maybe [SuggestionMatch] -> f (Maybe [SuggestionMatch]))
    -> Maybe [SuggestionMatch] -> f (Maybe [SuggestionMatch]))
-> (Maybe [SuggestionMatch] -> f (Maybe [SuggestionMatch]))
-> SuggestModel
-> f SuggestModel
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [SuggestionMatch]
  [SuggestionMatch]
  [SuggestionMatch]
  [SuggestionMatch]
-> Iso
     (Maybe [SuggestionMatch])
     (Maybe [SuggestionMatch])
     (Maybe [SuggestionMatch])
     (Maybe [SuggestionMatch])
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
  [SuggestionMatch]
  [SuggestionMatch]
  [SuggestionMatch]
  [SuggestionMatch]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The query string specified in the suggest request.
suggestModel_query :: Lens.Lens' SuggestModel (Prelude.Maybe Prelude.Text)
suggestModel_query :: (Maybe Text -> f (Maybe Text)) -> SuggestModel -> f SuggestModel
suggestModel_query = (SuggestModel -> Maybe Text)
-> (SuggestModel -> Maybe Text -> SuggestModel)
-> Lens SuggestModel SuggestModel (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SuggestModel' {Maybe Text
query :: Maybe Text
$sel:query:SuggestModel' :: SuggestModel -> Maybe Text
query} -> Maybe Text
query) (\s :: SuggestModel
s@SuggestModel' {} Maybe Text
a -> SuggestModel
s {$sel:query:SuggestModel' :: Maybe Text
query = Maybe Text
a} :: SuggestModel)

instance Core.FromJSON SuggestModel where
  parseJSON :: Value -> Parser SuggestModel
parseJSON =
    String
-> (Object -> Parser SuggestModel) -> Value -> Parser SuggestModel
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SuggestModel"
      ( \Object
x ->
          Maybe Integer
-> Maybe [SuggestionMatch] -> Maybe Text -> SuggestModel
SuggestModel'
            (Maybe Integer
 -> Maybe [SuggestionMatch] -> Maybe Text -> SuggestModel)
-> Parser (Maybe Integer)
-> Parser (Maybe [SuggestionMatch] -> Maybe Text -> SuggestModel)
forall (f :: * -> *) a b. Functor 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")
            Parser (Maybe [SuggestionMatch] -> Maybe Text -> SuggestModel)
-> Parser (Maybe [SuggestionMatch])
-> Parser (Maybe Text -> SuggestModel)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [SuggestionMatch]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"suggestions" Parser (Maybe (Maybe [SuggestionMatch]))
-> Maybe [SuggestionMatch] -> Parser (Maybe [SuggestionMatch])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [SuggestionMatch]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> SuggestModel)
-> Parser (Maybe Text) -> Parser SuggestModel
forall (f :: * -> *) a b. Applicative f => 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
"query")
      )

instance Prelude.Hashable SuggestModel

instance Prelude.NFData SuggestModel