{-# 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.IoT.Types.TermsAggregation
-- 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.IoT.Types.TermsAggregation where

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

-- | Performs an aggregation that will return a list of buckets. The list of
-- buckets is a ranked list of the number of occurrences of an aggregation
-- field value.
--
-- /See:/ 'newTermsAggregation' smart constructor.
data TermsAggregation = TermsAggregation'
  { -- | The number of buckets to return in the response. Default to 10.
    TermsAggregation -> Maybe Natural
maxBuckets :: Prelude.Maybe Prelude.Natural
  }
  deriving (TermsAggregation -> TermsAggregation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TermsAggregation -> TermsAggregation -> Bool
$c/= :: TermsAggregation -> TermsAggregation -> Bool
== :: TermsAggregation -> TermsAggregation -> Bool
$c== :: TermsAggregation -> TermsAggregation -> Bool
Prelude.Eq, ReadPrec [TermsAggregation]
ReadPrec TermsAggregation
Int -> ReadS TermsAggregation
ReadS [TermsAggregation]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TermsAggregation]
$creadListPrec :: ReadPrec [TermsAggregation]
readPrec :: ReadPrec TermsAggregation
$creadPrec :: ReadPrec TermsAggregation
readList :: ReadS [TermsAggregation]
$creadList :: ReadS [TermsAggregation]
readsPrec :: Int -> ReadS TermsAggregation
$creadsPrec :: Int -> ReadS TermsAggregation
Prelude.Read, Int -> TermsAggregation -> ShowS
[TermsAggregation] -> ShowS
TermsAggregation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TermsAggregation] -> ShowS
$cshowList :: [TermsAggregation] -> ShowS
show :: TermsAggregation -> String
$cshow :: TermsAggregation -> String
showsPrec :: Int -> TermsAggregation -> ShowS
$cshowsPrec :: Int -> TermsAggregation -> ShowS
Prelude.Show, forall x. Rep TermsAggregation x -> TermsAggregation
forall x. TermsAggregation -> Rep TermsAggregation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TermsAggregation x -> TermsAggregation
$cfrom :: forall x. TermsAggregation -> Rep TermsAggregation x
Prelude.Generic)

-- |
-- Create a value of 'TermsAggregation' 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:
--
-- 'maxBuckets', 'termsAggregation_maxBuckets' - The number of buckets to return in the response. Default to 10.
newTermsAggregation ::
  TermsAggregation
newTermsAggregation :: TermsAggregation
newTermsAggregation =
  TermsAggregation' {$sel:maxBuckets:TermsAggregation' :: Maybe Natural
maxBuckets = forall a. Maybe a
Prelude.Nothing}

-- | The number of buckets to return in the response. Default to 10.
termsAggregation_maxBuckets :: Lens.Lens' TermsAggregation (Prelude.Maybe Prelude.Natural)
termsAggregation_maxBuckets :: Lens' TermsAggregation (Maybe Natural)
termsAggregation_maxBuckets = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TermsAggregation' {Maybe Natural
maxBuckets :: Maybe Natural
$sel:maxBuckets:TermsAggregation' :: TermsAggregation -> Maybe Natural
maxBuckets} -> Maybe Natural
maxBuckets) (\s :: TermsAggregation
s@TermsAggregation' {} Maybe Natural
a -> TermsAggregation
s {$sel:maxBuckets:TermsAggregation' :: Maybe Natural
maxBuckets = Maybe Natural
a} :: TermsAggregation)

instance Prelude.Hashable TermsAggregation where
  hashWithSalt :: Int -> TermsAggregation -> Int
hashWithSalt Int
_salt TermsAggregation' {Maybe Natural
maxBuckets :: Maybe Natural
$sel:maxBuckets:TermsAggregation' :: TermsAggregation -> Maybe Natural
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxBuckets

instance Prelude.NFData TermsAggregation where
  rnf :: TermsAggregation -> ()
rnf TermsAggregation' {Maybe Natural
maxBuckets :: Maybe Natural
$sel:maxBuckets:TermsAggregation' :: TermsAggregation -> Maybe Natural
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxBuckets

instance Data.ToJSON TermsAggregation where
  toJSON :: TermsAggregation -> Value
toJSON TermsAggregation' {Maybe Natural
maxBuckets :: Maybe Natural
$sel:maxBuckets:TermsAggregation' :: TermsAggregation -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"maxBuckets" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxBuckets]
      )