{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.GetBucketsAggregation
-- 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)
--
-- Aggregates on indexed data with search queries pertaining to particular
-- fields.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions GetBucketsAggregation>
-- action.
module Amazonka.IoT.GetBucketsAggregation
  ( -- * Creating a Request
    GetBucketsAggregation (..),
    newGetBucketsAggregation,

    -- * Request Lenses
    getBucketsAggregation_queryVersion,
    getBucketsAggregation_indexName,
    getBucketsAggregation_queryString,
    getBucketsAggregation_aggregationField,
    getBucketsAggregation_bucketsAggregationType,

    -- * Destructuring the Response
    GetBucketsAggregationResponse (..),
    newGetBucketsAggregationResponse,

    -- * Response Lenses
    getBucketsAggregationResponse_buckets,
    getBucketsAggregationResponse_totalCount,
    getBucketsAggregationResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetBucketsAggregation' smart constructor.
data GetBucketsAggregation = GetBucketsAggregation'
  { -- | The version of the query.
    GetBucketsAggregation -> Maybe Text
queryVersion :: Prelude.Maybe Prelude.Text,
    -- | The name of the index to search.
    GetBucketsAggregation -> Maybe Text
indexName :: Prelude.Maybe Prelude.Text,
    -- | The search query string.
    GetBucketsAggregation -> Text
queryString :: Prelude.Text,
    -- | The aggregation field.
    GetBucketsAggregation -> Text
aggregationField :: Prelude.Text,
    -- | The basic control of the response shape and the bucket aggregation type
    -- to perform.
    GetBucketsAggregation -> BucketsAggregationType
bucketsAggregationType :: BucketsAggregationType
  }
  deriving (GetBucketsAggregation -> GetBucketsAggregation -> Bool
(GetBucketsAggregation -> GetBucketsAggregation -> Bool)
-> (GetBucketsAggregation -> GetBucketsAggregation -> Bool)
-> Eq GetBucketsAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketsAggregation -> GetBucketsAggregation -> Bool
$c/= :: GetBucketsAggregation -> GetBucketsAggregation -> Bool
== :: GetBucketsAggregation -> GetBucketsAggregation -> Bool
$c== :: GetBucketsAggregation -> GetBucketsAggregation -> Bool
Prelude.Eq, ReadPrec [GetBucketsAggregation]
ReadPrec GetBucketsAggregation
Int -> ReadS GetBucketsAggregation
ReadS [GetBucketsAggregation]
(Int -> ReadS GetBucketsAggregation)
-> ReadS [GetBucketsAggregation]
-> ReadPrec GetBucketsAggregation
-> ReadPrec [GetBucketsAggregation]
-> Read GetBucketsAggregation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketsAggregation]
$creadListPrec :: ReadPrec [GetBucketsAggregation]
readPrec :: ReadPrec GetBucketsAggregation
$creadPrec :: ReadPrec GetBucketsAggregation
readList :: ReadS [GetBucketsAggregation]
$creadList :: ReadS [GetBucketsAggregation]
readsPrec :: Int -> ReadS GetBucketsAggregation
$creadsPrec :: Int -> ReadS GetBucketsAggregation
Prelude.Read, Int -> GetBucketsAggregation -> ShowS
[GetBucketsAggregation] -> ShowS
GetBucketsAggregation -> String
(Int -> GetBucketsAggregation -> ShowS)
-> (GetBucketsAggregation -> String)
-> ([GetBucketsAggregation] -> ShowS)
-> Show GetBucketsAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketsAggregation] -> ShowS
$cshowList :: [GetBucketsAggregation] -> ShowS
show :: GetBucketsAggregation -> String
$cshow :: GetBucketsAggregation -> String
showsPrec :: Int -> GetBucketsAggregation -> ShowS
$cshowsPrec :: Int -> GetBucketsAggregation -> ShowS
Prelude.Show, (forall x. GetBucketsAggregation -> Rep GetBucketsAggregation x)
-> (forall x. Rep GetBucketsAggregation x -> GetBucketsAggregation)
-> Generic GetBucketsAggregation
forall x. Rep GetBucketsAggregation x -> GetBucketsAggregation
forall x. GetBucketsAggregation -> Rep GetBucketsAggregation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetBucketsAggregation x -> GetBucketsAggregation
$cfrom :: forall x. GetBucketsAggregation -> Rep GetBucketsAggregation x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketsAggregation' 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:
--
-- 'queryVersion', 'getBucketsAggregation_queryVersion' - The version of the query.
--
-- 'indexName', 'getBucketsAggregation_indexName' - The name of the index to search.
--
-- 'queryString', 'getBucketsAggregation_queryString' - The search query string.
--
-- 'aggregationField', 'getBucketsAggregation_aggregationField' - The aggregation field.
--
-- 'bucketsAggregationType', 'getBucketsAggregation_bucketsAggregationType' - The basic control of the response shape and the bucket aggregation type
-- to perform.
newGetBucketsAggregation ::
  -- | 'queryString'
  Prelude.Text ->
  -- | 'aggregationField'
  Prelude.Text ->
  -- | 'bucketsAggregationType'
  BucketsAggregationType ->
  GetBucketsAggregation
newGetBucketsAggregation :: Text -> Text -> BucketsAggregationType -> GetBucketsAggregation
newGetBucketsAggregation
  Text
pQueryString_
  Text
pAggregationField_
  BucketsAggregationType
pBucketsAggregationType_ =
    GetBucketsAggregation' :: Maybe Text
-> Maybe Text
-> Text
-> Text
-> BucketsAggregationType
-> GetBucketsAggregation
GetBucketsAggregation'
      { $sel:queryVersion:GetBucketsAggregation' :: Maybe Text
queryVersion =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:indexName:GetBucketsAggregation' :: Maybe Text
indexName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:queryString:GetBucketsAggregation' :: Text
queryString = Text
pQueryString_,
        $sel:aggregationField:GetBucketsAggregation' :: Text
aggregationField = Text
pAggregationField_,
        $sel:bucketsAggregationType:GetBucketsAggregation' :: BucketsAggregationType
bucketsAggregationType = BucketsAggregationType
pBucketsAggregationType_
      }

-- | The version of the query.
getBucketsAggregation_queryVersion :: Lens.Lens' GetBucketsAggregation (Prelude.Maybe Prelude.Text)
getBucketsAggregation_queryVersion :: (Maybe Text -> f (Maybe Text))
-> GetBucketsAggregation -> f GetBucketsAggregation
getBucketsAggregation_queryVersion = (GetBucketsAggregation -> Maybe Text)
-> (GetBucketsAggregation -> Maybe Text -> GetBucketsAggregation)
-> Lens
     GetBucketsAggregation
     GetBucketsAggregation
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketsAggregation' {Maybe Text
queryVersion :: Maybe Text
$sel:queryVersion:GetBucketsAggregation' :: GetBucketsAggregation -> Maybe Text
queryVersion} -> Maybe Text
queryVersion) (\s :: GetBucketsAggregation
s@GetBucketsAggregation' {} Maybe Text
a -> GetBucketsAggregation
s {$sel:queryVersion:GetBucketsAggregation' :: Maybe Text
queryVersion = Maybe Text
a} :: GetBucketsAggregation)

-- | The name of the index to search.
getBucketsAggregation_indexName :: Lens.Lens' GetBucketsAggregation (Prelude.Maybe Prelude.Text)
getBucketsAggregation_indexName :: (Maybe Text -> f (Maybe Text))
-> GetBucketsAggregation -> f GetBucketsAggregation
getBucketsAggregation_indexName = (GetBucketsAggregation -> Maybe Text)
-> (GetBucketsAggregation -> Maybe Text -> GetBucketsAggregation)
-> Lens
     GetBucketsAggregation
     GetBucketsAggregation
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketsAggregation' {Maybe Text
indexName :: Maybe Text
$sel:indexName:GetBucketsAggregation' :: GetBucketsAggregation -> Maybe Text
indexName} -> Maybe Text
indexName) (\s :: GetBucketsAggregation
s@GetBucketsAggregation' {} Maybe Text
a -> GetBucketsAggregation
s {$sel:indexName:GetBucketsAggregation' :: Maybe Text
indexName = Maybe Text
a} :: GetBucketsAggregation)

-- | The search query string.
getBucketsAggregation_queryString :: Lens.Lens' GetBucketsAggregation Prelude.Text
getBucketsAggregation_queryString :: (Text -> f Text)
-> GetBucketsAggregation -> f GetBucketsAggregation
getBucketsAggregation_queryString = (GetBucketsAggregation -> Text)
-> (GetBucketsAggregation -> Text -> GetBucketsAggregation)
-> Lens GetBucketsAggregation GetBucketsAggregation Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketsAggregation' {Text
queryString :: Text
$sel:queryString:GetBucketsAggregation' :: GetBucketsAggregation -> Text
queryString} -> Text
queryString) (\s :: GetBucketsAggregation
s@GetBucketsAggregation' {} Text
a -> GetBucketsAggregation
s {$sel:queryString:GetBucketsAggregation' :: Text
queryString = Text
a} :: GetBucketsAggregation)

-- | The aggregation field.
getBucketsAggregation_aggregationField :: Lens.Lens' GetBucketsAggregation Prelude.Text
getBucketsAggregation_aggregationField :: (Text -> f Text)
-> GetBucketsAggregation -> f GetBucketsAggregation
getBucketsAggregation_aggregationField = (GetBucketsAggregation -> Text)
-> (GetBucketsAggregation -> Text -> GetBucketsAggregation)
-> Lens GetBucketsAggregation GetBucketsAggregation Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketsAggregation' {Text
aggregationField :: Text
$sel:aggregationField:GetBucketsAggregation' :: GetBucketsAggregation -> Text
aggregationField} -> Text
aggregationField) (\s :: GetBucketsAggregation
s@GetBucketsAggregation' {} Text
a -> GetBucketsAggregation
s {$sel:aggregationField:GetBucketsAggregation' :: Text
aggregationField = Text
a} :: GetBucketsAggregation)

-- | The basic control of the response shape and the bucket aggregation type
-- to perform.
getBucketsAggregation_bucketsAggregationType :: Lens.Lens' GetBucketsAggregation BucketsAggregationType
getBucketsAggregation_bucketsAggregationType :: (BucketsAggregationType -> f BucketsAggregationType)
-> GetBucketsAggregation -> f GetBucketsAggregation
getBucketsAggregation_bucketsAggregationType = (GetBucketsAggregation -> BucketsAggregationType)
-> (GetBucketsAggregation
    -> BucketsAggregationType -> GetBucketsAggregation)
-> Lens
     GetBucketsAggregation
     GetBucketsAggregation
     BucketsAggregationType
     BucketsAggregationType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketsAggregation' {BucketsAggregationType
bucketsAggregationType :: BucketsAggregationType
$sel:bucketsAggregationType:GetBucketsAggregation' :: GetBucketsAggregation -> BucketsAggregationType
bucketsAggregationType} -> BucketsAggregationType
bucketsAggregationType) (\s :: GetBucketsAggregation
s@GetBucketsAggregation' {} BucketsAggregationType
a -> GetBucketsAggregation
s {$sel:bucketsAggregationType:GetBucketsAggregation' :: BucketsAggregationType
bucketsAggregationType = BucketsAggregationType
a} :: GetBucketsAggregation)

instance Core.AWSRequest GetBucketsAggregation where
  type
    AWSResponse GetBucketsAggregation =
      GetBucketsAggregationResponse
  request :: GetBucketsAggregation -> Request GetBucketsAggregation
request = Service -> GetBucketsAggregation -> Request GetBucketsAggregation
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetBucketsAggregation
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetBucketsAggregation)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetBucketsAggregation))
-> Logger
-> Service
-> Proxy GetBucketsAggregation
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetBucketsAggregation)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Bucket] -> Maybe Int -> Int -> GetBucketsAggregationResponse
GetBucketsAggregationResponse'
            (Maybe [Bucket]
 -> Maybe Int -> Int -> GetBucketsAggregationResponse)
-> Either String (Maybe [Bucket])
-> Either
     String (Maybe Int -> Int -> GetBucketsAggregationResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Bucket]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"buckets" Either String (Maybe (Maybe [Bucket]))
-> Maybe [Bucket] -> Either String (Maybe [Bucket])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Bucket]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Maybe Int -> Int -> GetBucketsAggregationResponse)
-> Either String (Maybe Int)
-> Either String (Int -> GetBucketsAggregationResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Int)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"totalCount")
            Either String (Int -> GetBucketsAggregationResponse)
-> Either String Int -> Either String GetBucketsAggregationResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetBucketsAggregation

instance Prelude.NFData GetBucketsAggregation

instance Core.ToHeaders GetBucketsAggregation where
  toHeaders :: GetBucketsAggregation -> ResponseHeaders
toHeaders = ResponseHeaders -> GetBucketsAggregation -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToPath GetBucketsAggregation where
  toPath :: GetBucketsAggregation -> ByteString
toPath = ByteString -> GetBucketsAggregation -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/indices/buckets"

instance Core.ToQuery GetBucketsAggregation where
  toQuery :: GetBucketsAggregation -> QueryString
toQuery = QueryString -> GetBucketsAggregation -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newGetBucketsAggregationResponse' smart constructor.
data GetBucketsAggregationResponse = GetBucketsAggregationResponse'
  { -- | The main part of the response with a list of buckets. Each bucket
    -- contains a @keyValue@ and a @count@.
    --
    -- @keyValue@: The aggregation field value counted for the particular
    -- bucket.
    --
    -- @count@: The number of documents that have that value.
    GetBucketsAggregationResponse -> Maybe [Bucket]
buckets :: Prelude.Maybe [Bucket],
    -- | The total number of documents that fit the query string criteria and
    -- contain a value for the Aggregation field targeted in the request.
    GetBucketsAggregationResponse -> Maybe Int
totalCount :: Prelude.Maybe Prelude.Int,
    -- | The response's http status code.
    GetBucketsAggregationResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetBucketsAggregationResponse
-> GetBucketsAggregationResponse -> Bool
(GetBucketsAggregationResponse
 -> GetBucketsAggregationResponse -> Bool)
-> (GetBucketsAggregationResponse
    -> GetBucketsAggregationResponse -> Bool)
-> Eq GetBucketsAggregationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketsAggregationResponse
-> GetBucketsAggregationResponse -> Bool
$c/= :: GetBucketsAggregationResponse
-> GetBucketsAggregationResponse -> Bool
== :: GetBucketsAggregationResponse
-> GetBucketsAggregationResponse -> Bool
$c== :: GetBucketsAggregationResponse
-> GetBucketsAggregationResponse -> Bool
Prelude.Eq, ReadPrec [GetBucketsAggregationResponse]
ReadPrec GetBucketsAggregationResponse
Int -> ReadS GetBucketsAggregationResponse
ReadS [GetBucketsAggregationResponse]
(Int -> ReadS GetBucketsAggregationResponse)
-> ReadS [GetBucketsAggregationResponse]
-> ReadPrec GetBucketsAggregationResponse
-> ReadPrec [GetBucketsAggregationResponse]
-> Read GetBucketsAggregationResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketsAggregationResponse]
$creadListPrec :: ReadPrec [GetBucketsAggregationResponse]
readPrec :: ReadPrec GetBucketsAggregationResponse
$creadPrec :: ReadPrec GetBucketsAggregationResponse
readList :: ReadS [GetBucketsAggregationResponse]
$creadList :: ReadS [GetBucketsAggregationResponse]
readsPrec :: Int -> ReadS GetBucketsAggregationResponse
$creadsPrec :: Int -> ReadS GetBucketsAggregationResponse
Prelude.Read, Int -> GetBucketsAggregationResponse -> ShowS
[GetBucketsAggregationResponse] -> ShowS
GetBucketsAggregationResponse -> String
(Int -> GetBucketsAggregationResponse -> ShowS)
-> (GetBucketsAggregationResponse -> String)
-> ([GetBucketsAggregationResponse] -> ShowS)
-> Show GetBucketsAggregationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketsAggregationResponse] -> ShowS
$cshowList :: [GetBucketsAggregationResponse] -> ShowS
show :: GetBucketsAggregationResponse -> String
$cshow :: GetBucketsAggregationResponse -> String
showsPrec :: Int -> GetBucketsAggregationResponse -> ShowS
$cshowsPrec :: Int -> GetBucketsAggregationResponse -> ShowS
Prelude.Show, (forall x.
 GetBucketsAggregationResponse
 -> Rep GetBucketsAggregationResponse x)
-> (forall x.
    Rep GetBucketsAggregationResponse x
    -> GetBucketsAggregationResponse)
-> Generic GetBucketsAggregationResponse
forall x.
Rep GetBucketsAggregationResponse x
-> GetBucketsAggregationResponse
forall x.
GetBucketsAggregationResponse
-> Rep GetBucketsAggregationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetBucketsAggregationResponse x
-> GetBucketsAggregationResponse
$cfrom :: forall x.
GetBucketsAggregationResponse
-> Rep GetBucketsAggregationResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketsAggregationResponse' 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:
--
-- 'buckets', 'getBucketsAggregationResponse_buckets' - The main part of the response with a list of buckets. Each bucket
-- contains a @keyValue@ and a @count@.
--
-- @keyValue@: The aggregation field value counted for the particular
-- bucket.
--
-- @count@: The number of documents that have that value.
--
-- 'totalCount', 'getBucketsAggregationResponse_totalCount' - The total number of documents that fit the query string criteria and
-- contain a value for the Aggregation field targeted in the request.
--
-- 'httpStatus', 'getBucketsAggregationResponse_httpStatus' - The response's http status code.
newGetBucketsAggregationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetBucketsAggregationResponse
newGetBucketsAggregationResponse :: Int -> GetBucketsAggregationResponse
newGetBucketsAggregationResponse Int
pHttpStatus_ =
  GetBucketsAggregationResponse' :: Maybe [Bucket] -> Maybe Int -> Int -> GetBucketsAggregationResponse
GetBucketsAggregationResponse'
    { $sel:buckets:GetBucketsAggregationResponse' :: Maybe [Bucket]
buckets =
        Maybe [Bucket]
forall a. Maybe a
Prelude.Nothing,
      $sel:totalCount:GetBucketsAggregationResponse' :: Maybe Int
totalCount = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetBucketsAggregationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The main part of the response with a list of buckets. Each bucket
-- contains a @keyValue@ and a @count@.
--
-- @keyValue@: The aggregation field value counted for the particular
-- bucket.
--
-- @count@: The number of documents that have that value.
getBucketsAggregationResponse_buckets :: Lens.Lens' GetBucketsAggregationResponse (Prelude.Maybe [Bucket])
getBucketsAggregationResponse_buckets :: (Maybe [Bucket] -> f (Maybe [Bucket]))
-> GetBucketsAggregationResponse -> f GetBucketsAggregationResponse
getBucketsAggregationResponse_buckets = (GetBucketsAggregationResponse -> Maybe [Bucket])
-> (GetBucketsAggregationResponse
    -> Maybe [Bucket] -> GetBucketsAggregationResponse)
-> Lens
     GetBucketsAggregationResponse
     GetBucketsAggregationResponse
     (Maybe [Bucket])
     (Maybe [Bucket])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketsAggregationResponse' {Maybe [Bucket]
buckets :: Maybe [Bucket]
$sel:buckets:GetBucketsAggregationResponse' :: GetBucketsAggregationResponse -> Maybe [Bucket]
buckets} -> Maybe [Bucket]
buckets) (\s :: GetBucketsAggregationResponse
s@GetBucketsAggregationResponse' {} Maybe [Bucket]
a -> GetBucketsAggregationResponse
s {$sel:buckets:GetBucketsAggregationResponse' :: Maybe [Bucket]
buckets = Maybe [Bucket]
a} :: GetBucketsAggregationResponse) ((Maybe [Bucket] -> f (Maybe [Bucket]))
 -> GetBucketsAggregationResponse
 -> f GetBucketsAggregationResponse)
-> ((Maybe [Bucket] -> f (Maybe [Bucket]))
    -> Maybe [Bucket] -> f (Maybe [Bucket]))
-> (Maybe [Bucket] -> f (Maybe [Bucket]))
-> GetBucketsAggregationResponse
-> f GetBucketsAggregationResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Bucket] [Bucket] [Bucket] [Bucket]
-> Iso
     (Maybe [Bucket]) (Maybe [Bucket]) (Maybe [Bucket]) (Maybe [Bucket])
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 [Bucket] [Bucket] [Bucket] [Bucket]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The total number of documents that fit the query string criteria and
-- contain a value for the Aggregation field targeted in the request.
getBucketsAggregationResponse_totalCount :: Lens.Lens' GetBucketsAggregationResponse (Prelude.Maybe Prelude.Int)
getBucketsAggregationResponse_totalCount :: (Maybe Int -> f (Maybe Int))
-> GetBucketsAggregationResponse -> f GetBucketsAggregationResponse
getBucketsAggregationResponse_totalCount = (GetBucketsAggregationResponse -> Maybe Int)
-> (GetBucketsAggregationResponse
    -> Maybe Int -> GetBucketsAggregationResponse)
-> Lens
     GetBucketsAggregationResponse
     GetBucketsAggregationResponse
     (Maybe Int)
     (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketsAggregationResponse' {Maybe Int
totalCount :: Maybe Int
$sel:totalCount:GetBucketsAggregationResponse' :: GetBucketsAggregationResponse -> Maybe Int
totalCount} -> Maybe Int
totalCount) (\s :: GetBucketsAggregationResponse
s@GetBucketsAggregationResponse' {} Maybe Int
a -> GetBucketsAggregationResponse
s {$sel:totalCount:GetBucketsAggregationResponse' :: Maybe Int
totalCount = Maybe Int
a} :: GetBucketsAggregationResponse)

-- | The response's http status code.
getBucketsAggregationResponse_httpStatus :: Lens.Lens' GetBucketsAggregationResponse Prelude.Int
getBucketsAggregationResponse_httpStatus :: (Int -> f Int)
-> GetBucketsAggregationResponse -> f GetBucketsAggregationResponse
getBucketsAggregationResponse_httpStatus = (GetBucketsAggregationResponse -> Int)
-> (GetBucketsAggregationResponse
    -> Int -> GetBucketsAggregationResponse)
-> Lens
     GetBucketsAggregationResponse GetBucketsAggregationResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketsAggregationResponse' {Int
httpStatus :: Int
$sel:httpStatus:GetBucketsAggregationResponse' :: GetBucketsAggregationResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: GetBucketsAggregationResponse
s@GetBucketsAggregationResponse' {} Int
a -> GetBucketsAggregationResponse
s {$sel:httpStatus:GetBucketsAggregationResponse' :: Int
httpStatus = Int
a} :: GetBucketsAggregationResponse)

instance Prelude.NFData GetBucketsAggregationResponse