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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import {-# SOURCE #-} Amazonka.Kendra.Types.DocumentAttributeValueCountPair
import Amazonka.Kendra.Types.DocumentAttributeValueType
import qualified Amazonka.Prelude as Prelude

-- | The facet values for the documents in the response.
--
-- /See:/ 'newFacetResult' smart constructor.
data FacetResult = FacetResult'
  { -- | The key for the facet values. This is the same as the
    -- @DocumentAttributeKey@ provided in the query.
    FacetResult -> Maybe Text
documentAttributeKey :: Prelude.Maybe Prelude.Text,
    -- | An array of key\/value pairs, where the key is the value of the
    -- attribute and the count is the number of documents that share the key
    -- value.
    FacetResult -> Maybe [DocumentAttributeValueCountPair]
documentAttributeValueCountPairs :: Prelude.Maybe [DocumentAttributeValueCountPair],
    -- | The data type of the facet value. This is the same as the type defined
    -- for the index field when it was created.
    FacetResult -> Maybe DocumentAttributeValueType
documentAttributeValueType :: Prelude.Maybe DocumentAttributeValueType
  }
  deriving (FacetResult -> FacetResult -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FacetResult -> FacetResult -> Bool
$c/= :: FacetResult -> FacetResult -> Bool
== :: FacetResult -> FacetResult -> Bool
$c== :: FacetResult -> FacetResult -> Bool
Prelude.Eq, ReadPrec [FacetResult]
ReadPrec FacetResult
Int -> ReadS FacetResult
ReadS [FacetResult]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FacetResult]
$creadListPrec :: ReadPrec [FacetResult]
readPrec :: ReadPrec FacetResult
$creadPrec :: ReadPrec FacetResult
readList :: ReadS [FacetResult]
$creadList :: ReadS [FacetResult]
readsPrec :: Int -> ReadS FacetResult
$creadsPrec :: Int -> ReadS FacetResult
Prelude.Read, Int -> FacetResult -> ShowS
[FacetResult] -> ShowS
FacetResult -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FacetResult] -> ShowS
$cshowList :: [FacetResult] -> ShowS
show :: FacetResult -> String
$cshow :: FacetResult -> String
showsPrec :: Int -> FacetResult -> ShowS
$cshowsPrec :: Int -> FacetResult -> ShowS
Prelude.Show, forall x. Rep FacetResult x -> FacetResult
forall x. FacetResult -> Rep FacetResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FacetResult x -> FacetResult
$cfrom :: forall x. FacetResult -> Rep FacetResult x
Prelude.Generic)

-- |
-- Create a value of 'FacetResult' 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:
--
-- 'documentAttributeKey', 'facetResult_documentAttributeKey' - The key for the facet values. This is the same as the
-- @DocumentAttributeKey@ provided in the query.
--
-- 'documentAttributeValueCountPairs', 'facetResult_documentAttributeValueCountPairs' - An array of key\/value pairs, where the key is the value of the
-- attribute and the count is the number of documents that share the key
-- value.
--
-- 'documentAttributeValueType', 'facetResult_documentAttributeValueType' - The data type of the facet value. This is the same as the type defined
-- for the index field when it was created.
newFacetResult ::
  FacetResult
newFacetResult :: FacetResult
newFacetResult =
  FacetResult'
    { $sel:documentAttributeKey:FacetResult' :: Maybe Text
documentAttributeKey =
        forall a. Maybe a
Prelude.Nothing,
      $sel:documentAttributeValueCountPairs:FacetResult' :: Maybe [DocumentAttributeValueCountPair]
documentAttributeValueCountPairs = forall a. Maybe a
Prelude.Nothing,
      $sel:documentAttributeValueType:FacetResult' :: Maybe DocumentAttributeValueType
documentAttributeValueType = forall a. Maybe a
Prelude.Nothing
    }

-- | The key for the facet values. This is the same as the
-- @DocumentAttributeKey@ provided in the query.
facetResult_documentAttributeKey :: Lens.Lens' FacetResult (Prelude.Maybe Prelude.Text)
facetResult_documentAttributeKey :: Lens' FacetResult (Maybe Text)
facetResult_documentAttributeKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetResult' {Maybe Text
documentAttributeKey :: Maybe Text
$sel:documentAttributeKey:FacetResult' :: FacetResult -> Maybe Text
documentAttributeKey} -> Maybe Text
documentAttributeKey) (\s :: FacetResult
s@FacetResult' {} Maybe Text
a -> FacetResult
s {$sel:documentAttributeKey:FacetResult' :: Maybe Text
documentAttributeKey = Maybe Text
a} :: FacetResult)

-- | An array of key\/value pairs, where the key is the value of the
-- attribute and the count is the number of documents that share the key
-- value.
facetResult_documentAttributeValueCountPairs :: Lens.Lens' FacetResult (Prelude.Maybe [DocumentAttributeValueCountPair])
facetResult_documentAttributeValueCountPairs :: Lens' FacetResult (Maybe [DocumentAttributeValueCountPair])
facetResult_documentAttributeValueCountPairs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetResult' {Maybe [DocumentAttributeValueCountPair]
documentAttributeValueCountPairs :: Maybe [DocumentAttributeValueCountPair]
$sel:documentAttributeValueCountPairs:FacetResult' :: FacetResult -> Maybe [DocumentAttributeValueCountPair]
documentAttributeValueCountPairs} -> Maybe [DocumentAttributeValueCountPair]
documentAttributeValueCountPairs) (\s :: FacetResult
s@FacetResult' {} Maybe [DocumentAttributeValueCountPair]
a -> FacetResult
s {$sel:documentAttributeValueCountPairs:FacetResult' :: Maybe [DocumentAttributeValueCountPair]
documentAttributeValueCountPairs = Maybe [DocumentAttributeValueCountPair]
a} :: FacetResult) 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 data type of the facet value. This is the same as the type defined
-- for the index field when it was created.
facetResult_documentAttributeValueType :: Lens.Lens' FacetResult (Prelude.Maybe DocumentAttributeValueType)
facetResult_documentAttributeValueType :: Lens' FacetResult (Maybe DocumentAttributeValueType)
facetResult_documentAttributeValueType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FacetResult' {Maybe DocumentAttributeValueType
documentAttributeValueType :: Maybe DocumentAttributeValueType
$sel:documentAttributeValueType:FacetResult' :: FacetResult -> Maybe DocumentAttributeValueType
documentAttributeValueType} -> Maybe DocumentAttributeValueType
documentAttributeValueType) (\s :: FacetResult
s@FacetResult' {} Maybe DocumentAttributeValueType
a -> FacetResult
s {$sel:documentAttributeValueType:FacetResult' :: Maybe DocumentAttributeValueType
documentAttributeValueType = Maybe DocumentAttributeValueType
a} :: FacetResult)

instance Data.FromJSON FacetResult where
  parseJSON :: Value -> Parser FacetResult
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FacetResult"
      ( \Object
x ->
          Maybe Text
-> Maybe [DocumentAttributeValueCountPair]
-> Maybe DocumentAttributeValueType
-> FacetResult
FacetResult'
            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
"DocumentAttributeKey")
            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
"DocumentAttributeValueCountPairs"
                            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
"DocumentAttributeValueType")
      )

instance Prelude.Hashable FacetResult where
  hashWithSalt :: Int -> FacetResult -> Int
hashWithSalt Int
_salt FacetResult' {Maybe [DocumentAttributeValueCountPair]
Maybe Text
Maybe DocumentAttributeValueType
documentAttributeValueType :: Maybe DocumentAttributeValueType
documentAttributeValueCountPairs :: Maybe [DocumentAttributeValueCountPair]
documentAttributeKey :: Maybe Text
$sel:documentAttributeValueType:FacetResult' :: FacetResult -> Maybe DocumentAttributeValueType
$sel:documentAttributeValueCountPairs:FacetResult' :: FacetResult -> Maybe [DocumentAttributeValueCountPair]
$sel:documentAttributeKey:FacetResult' :: FacetResult -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
documentAttributeKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [DocumentAttributeValueCountPair]
documentAttributeValueCountPairs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DocumentAttributeValueType
documentAttributeValueType

instance Prelude.NFData FacetResult where
  rnf :: FacetResult -> ()
rnf FacetResult' {Maybe [DocumentAttributeValueCountPair]
Maybe Text
Maybe DocumentAttributeValueType
documentAttributeValueType :: Maybe DocumentAttributeValueType
documentAttributeValueCountPairs :: Maybe [DocumentAttributeValueCountPair]
documentAttributeKey :: Maybe Text
$sel:documentAttributeValueType:FacetResult' :: FacetResult -> Maybe DocumentAttributeValueType
$sel:documentAttributeValueCountPairs:FacetResult' :: FacetResult -> Maybe [DocumentAttributeValueCountPair]
$sel:documentAttributeKey:FacetResult' :: FacetResult -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
documentAttributeKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [DocumentAttributeValueCountPair]
documentAttributeValueCountPairs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe DocumentAttributeValueType
documentAttributeValueType