{-# 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.GetStatistics
-- 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)
--
-- Returns the count, average, sum, minimum, maximum, sum of squares,
-- variance, and standard deviation for the specified aggregated field. If
-- the aggregation field is of type @String@, only the count statistic is
-- returned.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions GetStatistics>
-- action.
module Amazonka.IoT.GetStatistics
  ( -- * Creating a Request
    GetStatistics (..),
    newGetStatistics,

    -- * Request Lenses
    getStatistics_queryVersion,
    getStatistics_aggregationField,
    getStatistics_indexName,
    getStatistics_queryString,

    -- * Destructuring the Response
    GetStatisticsResponse (..),
    newGetStatisticsResponse,

    -- * Response Lenses
    getStatisticsResponse_statistics,
    getStatisticsResponse_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:/ 'newGetStatistics' smart constructor.
data GetStatistics = GetStatistics'
  { -- | The version of the query used to search.
    GetStatistics -> Maybe Text
queryVersion :: Prelude.Maybe Prelude.Text,
    -- | The aggregation field name.
    GetStatistics -> Maybe Text
aggregationField :: Prelude.Maybe Prelude.Text,
    -- | The name of the index to search. The default value is @AWS_Things@.
    GetStatistics -> Maybe Text
indexName :: Prelude.Maybe Prelude.Text,
    -- | The query used to search. You can specify \"*\" for the query string to
    -- get the count of all indexed things in your Amazon Web Services account.
    GetStatistics -> Text
queryString :: Prelude.Text
  }
  deriving (GetStatistics -> GetStatistics -> Bool
(GetStatistics -> GetStatistics -> Bool)
-> (GetStatistics -> GetStatistics -> Bool) -> Eq GetStatistics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetStatistics -> GetStatistics -> Bool
$c/= :: GetStatistics -> GetStatistics -> Bool
== :: GetStatistics -> GetStatistics -> Bool
$c== :: GetStatistics -> GetStatistics -> Bool
Prelude.Eq, ReadPrec [GetStatistics]
ReadPrec GetStatistics
Int -> ReadS GetStatistics
ReadS [GetStatistics]
(Int -> ReadS GetStatistics)
-> ReadS [GetStatistics]
-> ReadPrec GetStatistics
-> ReadPrec [GetStatistics]
-> Read GetStatistics
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetStatistics]
$creadListPrec :: ReadPrec [GetStatistics]
readPrec :: ReadPrec GetStatistics
$creadPrec :: ReadPrec GetStatistics
readList :: ReadS [GetStatistics]
$creadList :: ReadS [GetStatistics]
readsPrec :: Int -> ReadS GetStatistics
$creadsPrec :: Int -> ReadS GetStatistics
Prelude.Read, Int -> GetStatistics -> ShowS
[GetStatistics] -> ShowS
GetStatistics -> String
(Int -> GetStatistics -> ShowS)
-> (GetStatistics -> String)
-> ([GetStatistics] -> ShowS)
-> Show GetStatistics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetStatistics] -> ShowS
$cshowList :: [GetStatistics] -> ShowS
show :: GetStatistics -> String
$cshow :: GetStatistics -> String
showsPrec :: Int -> GetStatistics -> ShowS
$cshowsPrec :: Int -> GetStatistics -> ShowS
Prelude.Show, (forall x. GetStatistics -> Rep GetStatistics x)
-> (forall x. Rep GetStatistics x -> GetStatistics)
-> Generic GetStatistics
forall x. Rep GetStatistics x -> GetStatistics
forall x. GetStatistics -> Rep GetStatistics x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetStatistics x -> GetStatistics
$cfrom :: forall x. GetStatistics -> Rep GetStatistics x
Prelude.Generic)

-- |
-- Create a value of 'GetStatistics' 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', 'getStatistics_queryVersion' - The version of the query used to search.
--
-- 'aggregationField', 'getStatistics_aggregationField' - The aggregation field name.
--
-- 'indexName', 'getStatistics_indexName' - The name of the index to search. The default value is @AWS_Things@.
--
-- 'queryString', 'getStatistics_queryString' - The query used to search. You can specify \"*\" for the query string to
-- get the count of all indexed things in your Amazon Web Services account.
newGetStatistics ::
  -- | 'queryString'
  Prelude.Text ->
  GetStatistics
newGetStatistics :: Text -> GetStatistics
newGetStatistics Text
pQueryString_ =
  GetStatistics' :: Maybe Text -> Maybe Text -> Maybe Text -> Text -> GetStatistics
GetStatistics'
    { $sel:queryVersion:GetStatistics' :: Maybe Text
queryVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:aggregationField:GetStatistics' :: Maybe Text
aggregationField = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:indexName:GetStatistics' :: Maybe Text
indexName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:queryString:GetStatistics' :: Text
queryString = Text
pQueryString_
    }

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

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

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

-- | The query used to search. You can specify \"*\" for the query string to
-- get the count of all indexed things in your Amazon Web Services account.
getStatistics_queryString :: Lens.Lens' GetStatistics Prelude.Text
getStatistics_queryString :: (Text -> f Text) -> GetStatistics -> f GetStatistics
getStatistics_queryString = (GetStatistics -> Text)
-> (GetStatistics -> Text -> GetStatistics)
-> Lens GetStatistics GetStatistics Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetStatistics' {Text
queryString :: Text
$sel:queryString:GetStatistics' :: GetStatistics -> Text
queryString} -> Text
queryString) (\s :: GetStatistics
s@GetStatistics' {} Text
a -> GetStatistics
s {$sel:queryString:GetStatistics' :: Text
queryString = Text
a} :: GetStatistics)

instance Core.AWSRequest GetStatistics where
  type
    AWSResponse GetStatistics =
      GetStatisticsResponse
  request :: GetStatistics -> Request GetStatistics
request = Service -> GetStatistics -> Request GetStatistics
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetStatistics
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetStatistics)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetStatistics))
-> Logger
-> Service
-> Proxy GetStatistics
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetStatistics)))
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 Statistics -> Int -> GetStatisticsResponse
GetStatisticsResponse'
            (Maybe Statistics -> Int -> GetStatisticsResponse)
-> Either String (Maybe Statistics)
-> Either String (Int -> GetStatisticsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Statistics)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"statistics")
            Either String (Int -> GetStatisticsResponse)
-> Either String Int -> Either String GetStatisticsResponse
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 GetStatistics

instance Prelude.NFData GetStatistics

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

instance Core.ToJSON GetStatistics where
  toJSON :: GetStatistics -> Value
toJSON GetStatistics' {Maybe Text
Text
queryString :: Text
indexName :: Maybe Text
aggregationField :: Maybe Text
queryVersion :: Maybe Text
$sel:queryString:GetStatistics' :: GetStatistics -> Text
$sel:indexName:GetStatistics' :: GetStatistics -> Maybe Text
$sel:aggregationField:GetStatistics' :: GetStatistics -> Maybe Text
$sel:queryVersion:GetStatistics' :: GetStatistics -> 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
"aggregationField" 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
aggregationField,
            (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)
          ]
      )

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

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

-- | /See:/ 'newGetStatisticsResponse' smart constructor.
data GetStatisticsResponse = GetStatisticsResponse'
  { -- | The statistics returned by the Fleet Indexing service based on the query
    -- and aggregation field.
    GetStatisticsResponse -> Maybe Statistics
statistics :: Prelude.Maybe Statistics,
    -- | The response's http status code.
    GetStatisticsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetStatisticsResponse -> GetStatisticsResponse -> Bool
(GetStatisticsResponse -> GetStatisticsResponse -> Bool)
-> (GetStatisticsResponse -> GetStatisticsResponse -> Bool)
-> Eq GetStatisticsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetStatisticsResponse -> GetStatisticsResponse -> Bool
$c/= :: GetStatisticsResponse -> GetStatisticsResponse -> Bool
== :: GetStatisticsResponse -> GetStatisticsResponse -> Bool
$c== :: GetStatisticsResponse -> GetStatisticsResponse -> Bool
Prelude.Eq, ReadPrec [GetStatisticsResponse]
ReadPrec GetStatisticsResponse
Int -> ReadS GetStatisticsResponse
ReadS [GetStatisticsResponse]
(Int -> ReadS GetStatisticsResponse)
-> ReadS [GetStatisticsResponse]
-> ReadPrec GetStatisticsResponse
-> ReadPrec [GetStatisticsResponse]
-> Read GetStatisticsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetStatisticsResponse]
$creadListPrec :: ReadPrec [GetStatisticsResponse]
readPrec :: ReadPrec GetStatisticsResponse
$creadPrec :: ReadPrec GetStatisticsResponse
readList :: ReadS [GetStatisticsResponse]
$creadList :: ReadS [GetStatisticsResponse]
readsPrec :: Int -> ReadS GetStatisticsResponse
$creadsPrec :: Int -> ReadS GetStatisticsResponse
Prelude.Read, Int -> GetStatisticsResponse -> ShowS
[GetStatisticsResponse] -> ShowS
GetStatisticsResponse -> String
(Int -> GetStatisticsResponse -> ShowS)
-> (GetStatisticsResponse -> String)
-> ([GetStatisticsResponse] -> ShowS)
-> Show GetStatisticsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetStatisticsResponse] -> ShowS
$cshowList :: [GetStatisticsResponse] -> ShowS
show :: GetStatisticsResponse -> String
$cshow :: GetStatisticsResponse -> String
showsPrec :: Int -> GetStatisticsResponse -> ShowS
$cshowsPrec :: Int -> GetStatisticsResponse -> ShowS
Prelude.Show, (forall x. GetStatisticsResponse -> Rep GetStatisticsResponse x)
-> (forall x. Rep GetStatisticsResponse x -> GetStatisticsResponse)
-> Generic GetStatisticsResponse
forall x. Rep GetStatisticsResponse x -> GetStatisticsResponse
forall x. GetStatisticsResponse -> Rep GetStatisticsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetStatisticsResponse x -> GetStatisticsResponse
$cfrom :: forall x. GetStatisticsResponse -> Rep GetStatisticsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetStatisticsResponse' 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:
--
-- 'statistics', 'getStatisticsResponse_statistics' - The statistics returned by the Fleet Indexing service based on the query
-- and aggregation field.
--
-- 'httpStatus', 'getStatisticsResponse_httpStatus' - The response's http status code.
newGetStatisticsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetStatisticsResponse
newGetStatisticsResponse :: Int -> GetStatisticsResponse
newGetStatisticsResponse Int
pHttpStatus_ =
  GetStatisticsResponse' :: Maybe Statistics -> Int -> GetStatisticsResponse
GetStatisticsResponse'
    { $sel:statistics:GetStatisticsResponse' :: Maybe Statistics
statistics =
        Maybe Statistics
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetStatisticsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The statistics returned by the Fleet Indexing service based on the query
-- and aggregation field.
getStatisticsResponse_statistics :: Lens.Lens' GetStatisticsResponse (Prelude.Maybe Statistics)
getStatisticsResponse_statistics :: (Maybe Statistics -> f (Maybe Statistics))
-> GetStatisticsResponse -> f GetStatisticsResponse
getStatisticsResponse_statistics = (GetStatisticsResponse -> Maybe Statistics)
-> (GetStatisticsResponse
    -> Maybe Statistics -> GetStatisticsResponse)
-> Lens
     GetStatisticsResponse
     GetStatisticsResponse
     (Maybe Statistics)
     (Maybe Statistics)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetStatisticsResponse' {Maybe Statistics
statistics :: Maybe Statistics
$sel:statistics:GetStatisticsResponse' :: GetStatisticsResponse -> Maybe Statistics
statistics} -> Maybe Statistics
statistics) (\s :: GetStatisticsResponse
s@GetStatisticsResponse' {} Maybe Statistics
a -> GetStatisticsResponse
s {$sel:statistics:GetStatisticsResponse' :: Maybe Statistics
statistics = Maybe Statistics
a} :: GetStatisticsResponse)

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

instance Prelude.NFData GetStatisticsResponse