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

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.TermsAggregation
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The type of bucketed aggregation performed.
--
-- /See:/ 'newBucketsAggregationType' smart constructor.
data BucketsAggregationType = BucketsAggregationType'
  { -- | 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.
    BucketsAggregationType -> Maybe TermsAggregation
termsAggregation :: Prelude.Maybe TermsAggregation
  }
  deriving (BucketsAggregationType -> BucketsAggregationType -> Bool
(BucketsAggregationType -> BucketsAggregationType -> Bool)
-> (BucketsAggregationType -> BucketsAggregationType -> Bool)
-> Eq BucketsAggregationType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BucketsAggregationType -> BucketsAggregationType -> Bool
$c/= :: BucketsAggregationType -> BucketsAggregationType -> Bool
== :: BucketsAggregationType -> BucketsAggregationType -> Bool
$c== :: BucketsAggregationType -> BucketsAggregationType -> Bool
Prelude.Eq, ReadPrec [BucketsAggregationType]
ReadPrec BucketsAggregationType
Int -> ReadS BucketsAggregationType
ReadS [BucketsAggregationType]
(Int -> ReadS BucketsAggregationType)
-> ReadS [BucketsAggregationType]
-> ReadPrec BucketsAggregationType
-> ReadPrec [BucketsAggregationType]
-> Read BucketsAggregationType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BucketsAggregationType]
$creadListPrec :: ReadPrec [BucketsAggregationType]
readPrec :: ReadPrec BucketsAggregationType
$creadPrec :: ReadPrec BucketsAggregationType
readList :: ReadS [BucketsAggregationType]
$creadList :: ReadS [BucketsAggregationType]
readsPrec :: Int -> ReadS BucketsAggregationType
$creadsPrec :: Int -> ReadS BucketsAggregationType
Prelude.Read, Int -> BucketsAggregationType -> ShowS
[BucketsAggregationType] -> ShowS
BucketsAggregationType -> String
(Int -> BucketsAggregationType -> ShowS)
-> (BucketsAggregationType -> String)
-> ([BucketsAggregationType] -> ShowS)
-> Show BucketsAggregationType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BucketsAggregationType] -> ShowS
$cshowList :: [BucketsAggregationType] -> ShowS
show :: BucketsAggregationType -> String
$cshow :: BucketsAggregationType -> String
showsPrec :: Int -> BucketsAggregationType -> ShowS
$cshowsPrec :: Int -> BucketsAggregationType -> ShowS
Prelude.Show, (forall x. BucketsAggregationType -> Rep BucketsAggregationType x)
-> (forall x.
    Rep BucketsAggregationType x -> BucketsAggregationType)
-> Generic BucketsAggregationType
forall x. Rep BucketsAggregationType x -> BucketsAggregationType
forall x. BucketsAggregationType -> Rep BucketsAggregationType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BucketsAggregationType x -> BucketsAggregationType
$cfrom :: forall x. BucketsAggregationType -> Rep BucketsAggregationType x
Prelude.Generic)

-- |
-- Create a value of 'BucketsAggregationType' 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:
--
-- 'termsAggregation', 'bucketsAggregationType_termsAggregation' - 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.
newBucketsAggregationType ::
  BucketsAggregationType
newBucketsAggregationType :: BucketsAggregationType
newBucketsAggregationType =
  BucketsAggregationType' :: Maybe TermsAggregation -> BucketsAggregationType
BucketsAggregationType'
    { $sel:termsAggregation:BucketsAggregationType' :: Maybe TermsAggregation
termsAggregation =
        Maybe TermsAggregation
forall a. Maybe a
Prelude.Nothing
    }

-- | 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.
bucketsAggregationType_termsAggregation :: Lens.Lens' BucketsAggregationType (Prelude.Maybe TermsAggregation)
bucketsAggregationType_termsAggregation :: (Maybe TermsAggregation -> f (Maybe TermsAggregation))
-> BucketsAggregationType -> f BucketsAggregationType
bucketsAggregationType_termsAggregation = (BucketsAggregationType -> Maybe TermsAggregation)
-> (BucketsAggregationType
    -> Maybe TermsAggregation -> BucketsAggregationType)
-> Lens
     BucketsAggregationType
     BucketsAggregationType
     (Maybe TermsAggregation)
     (Maybe TermsAggregation)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BucketsAggregationType' {Maybe TermsAggregation
termsAggregation :: Maybe TermsAggregation
$sel:termsAggregation:BucketsAggregationType' :: BucketsAggregationType -> Maybe TermsAggregation
termsAggregation} -> Maybe TermsAggregation
termsAggregation) (\s :: BucketsAggregationType
s@BucketsAggregationType' {} Maybe TermsAggregation
a -> BucketsAggregationType
s {$sel:termsAggregation:BucketsAggregationType' :: Maybe TermsAggregation
termsAggregation = Maybe TermsAggregation
a} :: BucketsAggregationType)

instance Prelude.Hashable BucketsAggregationType

instance Prelude.NFData BucketsAggregationType

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