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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(TermsAggregation -> TermsAggregation -> Bool)
-> (TermsAggregation -> TermsAggregation -> Bool)
-> Eq TermsAggregation
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]
(Int -> ReadS TermsAggregation)
-> ReadS [TermsAggregation]
-> ReadPrec TermsAggregation
-> ReadPrec [TermsAggregation]
-> Read 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
(Int -> TermsAggregation -> ShowS)
-> (TermsAggregation -> String)
-> ([TermsAggregation] -> ShowS)
-> Show TermsAggregation
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. TermsAggregation -> Rep TermsAggregation x)
-> (forall x. Rep TermsAggregation x -> TermsAggregation)
-> Generic TermsAggregation
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' :: Maybe Natural -> TermsAggregation
TermsAggregation' {$sel:maxBuckets:TermsAggregation' :: Maybe Natural
maxBuckets = Maybe Natural
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 :: (Maybe Natural -> f (Maybe Natural))
-> TermsAggregation -> f TermsAggregation
termsAggregation_maxBuckets = (TermsAggregation -> Maybe Natural)
-> (TermsAggregation -> Maybe Natural -> TermsAggregation)
-> Lens
     TermsAggregation TermsAggregation (Maybe Natural) (Maybe Natural)
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

instance Prelude.NFData TermsAggregation

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