{-# 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.SES.GetSendStatistics
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Provides sending statistics for the current AWS Region. The result is a
-- list of data points, representing the last two weeks of sending
-- activity. Each data point in the list contains statistics for a
-- 15-minute period of time.
--
-- You can execute this operation no more than once per second.
module Amazonka.SES.GetSendStatistics
  ( -- * Creating a Request
    GetSendStatistics (..),
    newGetSendStatistics,

    -- * Destructuring the Response
    GetSendStatisticsResponse (..),
    newGetSendStatisticsResponse,

    -- * Response Lenses
    getSendStatisticsResponse_sendDataPoints,
    getSendStatisticsResponse_httpStatus,
  )
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SES.Types

-- | /See:/ 'newGetSendStatistics' smart constructor.
data GetSendStatistics = GetSendStatistics'
  {
  }
  deriving (GetSendStatistics -> GetSendStatistics -> Bool
(GetSendStatistics -> GetSendStatistics -> Bool)
-> (GetSendStatistics -> GetSendStatistics -> Bool)
-> Eq GetSendStatistics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetSendStatistics -> GetSendStatistics -> Bool
== :: GetSendStatistics -> GetSendStatistics -> Bool
$c/= :: GetSendStatistics -> GetSendStatistics -> Bool
/= :: GetSendStatistics -> GetSendStatistics -> Bool
Prelude.Eq, ReadPrec [GetSendStatistics]
ReadPrec GetSendStatistics
Int -> ReadS GetSendStatistics
ReadS [GetSendStatistics]
(Int -> ReadS GetSendStatistics)
-> ReadS [GetSendStatistics]
-> ReadPrec GetSendStatistics
-> ReadPrec [GetSendStatistics]
-> Read GetSendStatistics
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS GetSendStatistics
readsPrec :: Int -> ReadS GetSendStatistics
$creadList :: ReadS [GetSendStatistics]
readList :: ReadS [GetSendStatistics]
$creadPrec :: ReadPrec GetSendStatistics
readPrec :: ReadPrec GetSendStatistics
$creadListPrec :: ReadPrec [GetSendStatistics]
readListPrec :: ReadPrec [GetSendStatistics]
Prelude.Read, Int -> GetSendStatistics -> ShowS
[GetSendStatistics] -> ShowS
GetSendStatistics -> String
(Int -> GetSendStatistics -> ShowS)
-> (GetSendStatistics -> String)
-> ([GetSendStatistics] -> ShowS)
-> Show GetSendStatistics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetSendStatistics -> ShowS
showsPrec :: Int -> GetSendStatistics -> ShowS
$cshow :: GetSendStatistics -> String
show :: GetSendStatistics -> String
$cshowList :: [GetSendStatistics] -> ShowS
showList :: [GetSendStatistics] -> ShowS
Prelude.Show, (forall x. GetSendStatistics -> Rep GetSendStatistics x)
-> (forall x. Rep GetSendStatistics x -> GetSendStatistics)
-> Generic GetSendStatistics
forall x. Rep GetSendStatistics x -> GetSendStatistics
forall x. GetSendStatistics -> Rep GetSendStatistics x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. GetSendStatistics -> Rep GetSendStatistics x
from :: forall x. GetSendStatistics -> Rep GetSendStatistics x
$cto :: forall x. Rep GetSendStatistics x -> GetSendStatistics
to :: forall x. Rep GetSendStatistics x -> GetSendStatistics
Prelude.Generic)

-- |
-- Create a value of 'GetSendStatistics' 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.
newGetSendStatistics ::
  GetSendStatistics
newGetSendStatistics :: GetSendStatistics
newGetSendStatistics = GetSendStatistics
GetSendStatistics'

instance Core.AWSRequest GetSendStatistics where
  type
    AWSResponse GetSendStatistics =
      GetSendStatisticsResponse
  request :: (Service -> Service)
-> GetSendStatistics -> Request GetSendStatistics
request Service -> Service
overrides =
    Service -> GetSendStatistics -> Request GetSendStatistics
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetSendStatistics
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetSendStatistics)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse GetSendStatistics))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetSendStatistics
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetSendStatistics)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"GetSendStatisticsResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [SendDataPoint] -> Int -> GetSendStatisticsResponse
GetSendStatisticsResponse'
            (Maybe [SendDataPoint] -> Int -> GetSendStatisticsResponse)
-> Either String (Maybe [SendDataPoint])
-> Either String (Int -> GetSendStatisticsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                            [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"SendDataPoints"
                            Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                            Either String [Node]
-> ([Node] -> Either String (Maybe [SendDataPoint]))
-> Either String (Maybe [SendDataPoint])
forall a b.
Either String a -> (a -> Either String b) -> Either String b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [SendDataPoint])
-> [Node] -> Either String (Maybe [SendDataPoint])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [SendDataPoint]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                        )
            Either String (Int -> GetSendStatisticsResponse)
-> Either String Int -> Either String GetSendStatisticsResponse
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall a. a -> Either String a
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 GetSendStatistics where
  hashWithSalt :: Int -> GetSendStatistics -> Int
hashWithSalt Int
_salt GetSendStatistics
_ =
    Int
_salt Int -> () -> Int
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ()

instance Prelude.NFData GetSendStatistics where
  rnf :: GetSendStatistics -> ()
rnf GetSendStatistics
_ = ()

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

instance Data.ToPath GetSendStatistics where
  toPath :: GetSendStatistics -> ByteString
toPath = ByteString -> GetSendStatistics -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery GetSendStatistics where
  toQuery :: GetSendStatistics -> QueryString
toQuery =
    QueryString -> GetSendStatistics -> QueryString
forall a b. a -> b -> a
Prelude.const
      ( [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ ByteString
"Action"
              ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"GetSendStatistics" :: Prelude.ByteString),
            ByteString
"Version"
              ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-12-01" :: Prelude.ByteString)
          ]
      )

-- | Represents a list of data points. This list contains aggregated data
-- from the previous two weeks of your sending activity with Amazon SES.
--
-- /See:/ 'newGetSendStatisticsResponse' smart constructor.
data GetSendStatisticsResponse = GetSendStatisticsResponse'
  { -- | A list of data points, each of which represents 15 minutes of activity.
    GetSendStatisticsResponse -> Maybe [SendDataPoint]
sendDataPoints :: Prelude.Maybe [SendDataPoint],
    -- | The response's http status code.
    GetSendStatisticsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
(GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool)
-> (GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool)
-> Eq GetSendStatisticsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
== :: GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
$c/= :: GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
/= :: GetSendStatisticsResponse -> GetSendStatisticsResponse -> Bool
Prelude.Eq, ReadPrec [GetSendStatisticsResponse]
ReadPrec GetSendStatisticsResponse
Int -> ReadS GetSendStatisticsResponse
ReadS [GetSendStatisticsResponse]
(Int -> ReadS GetSendStatisticsResponse)
-> ReadS [GetSendStatisticsResponse]
-> ReadPrec GetSendStatisticsResponse
-> ReadPrec [GetSendStatisticsResponse]
-> Read GetSendStatisticsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS GetSendStatisticsResponse
readsPrec :: Int -> ReadS GetSendStatisticsResponse
$creadList :: ReadS [GetSendStatisticsResponse]
readList :: ReadS [GetSendStatisticsResponse]
$creadPrec :: ReadPrec GetSendStatisticsResponse
readPrec :: ReadPrec GetSendStatisticsResponse
$creadListPrec :: ReadPrec [GetSendStatisticsResponse]
readListPrec :: ReadPrec [GetSendStatisticsResponse]
Prelude.Read, Int -> GetSendStatisticsResponse -> ShowS
[GetSendStatisticsResponse] -> ShowS
GetSendStatisticsResponse -> String
(Int -> GetSendStatisticsResponse -> ShowS)
-> (GetSendStatisticsResponse -> String)
-> ([GetSendStatisticsResponse] -> ShowS)
-> Show GetSendStatisticsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetSendStatisticsResponse -> ShowS
showsPrec :: Int -> GetSendStatisticsResponse -> ShowS
$cshow :: GetSendStatisticsResponse -> String
show :: GetSendStatisticsResponse -> String
$cshowList :: [GetSendStatisticsResponse] -> ShowS
showList :: [GetSendStatisticsResponse] -> ShowS
Prelude.Show, (forall x.
 GetSendStatisticsResponse -> Rep GetSendStatisticsResponse x)
-> (forall x.
    Rep GetSendStatisticsResponse x -> GetSendStatisticsResponse)
-> Generic GetSendStatisticsResponse
forall x.
Rep GetSendStatisticsResponse x -> GetSendStatisticsResponse
forall x.
GetSendStatisticsResponse -> Rep GetSendStatisticsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
GetSendStatisticsResponse -> Rep GetSendStatisticsResponse x
from :: forall x.
GetSendStatisticsResponse -> Rep GetSendStatisticsResponse x
$cto :: forall x.
Rep GetSendStatisticsResponse x -> GetSendStatisticsResponse
to :: forall x.
Rep GetSendStatisticsResponse x -> GetSendStatisticsResponse
Prelude.Generic)

-- |
-- Create a value of 'GetSendStatisticsResponse' 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:
--
-- 'sendDataPoints', 'getSendStatisticsResponse_sendDataPoints' - A list of data points, each of which represents 15 minutes of activity.
--
-- 'httpStatus', 'getSendStatisticsResponse_httpStatus' - The response's http status code.
newGetSendStatisticsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetSendStatisticsResponse
newGetSendStatisticsResponse :: Int -> GetSendStatisticsResponse
newGetSendStatisticsResponse Int
pHttpStatus_ =
  GetSendStatisticsResponse'
    { $sel:sendDataPoints:GetSendStatisticsResponse' :: Maybe [SendDataPoint]
sendDataPoints =
        Maybe [SendDataPoint]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetSendStatisticsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of data points, each of which represents 15 minutes of activity.
getSendStatisticsResponse_sendDataPoints :: Lens.Lens' GetSendStatisticsResponse (Prelude.Maybe [SendDataPoint])
getSendStatisticsResponse_sendDataPoints :: Lens' GetSendStatisticsResponse (Maybe [SendDataPoint])
getSendStatisticsResponse_sendDataPoints = (GetSendStatisticsResponse -> Maybe [SendDataPoint])
-> (GetSendStatisticsResponse
    -> Maybe [SendDataPoint] -> GetSendStatisticsResponse)
-> Lens' GetSendStatisticsResponse (Maybe [SendDataPoint])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSendStatisticsResponse' {Maybe [SendDataPoint]
$sel:sendDataPoints:GetSendStatisticsResponse' :: GetSendStatisticsResponse -> Maybe [SendDataPoint]
sendDataPoints :: Maybe [SendDataPoint]
sendDataPoints} -> Maybe [SendDataPoint]
sendDataPoints) (\s :: GetSendStatisticsResponse
s@GetSendStatisticsResponse' {} Maybe [SendDataPoint]
a -> GetSendStatisticsResponse
s {sendDataPoints = a} :: GetSendStatisticsResponse) ((Maybe [SendDataPoint] -> f (Maybe [SendDataPoint]))
 -> GetSendStatisticsResponse -> f GetSendStatisticsResponse)
-> ((Maybe [SendDataPoint] -> f (Maybe [SendDataPoint]))
    -> Maybe [SendDataPoint] -> f (Maybe [SendDataPoint]))
-> (Maybe [SendDataPoint] -> f (Maybe [SendDataPoint]))
-> GetSendStatisticsResponse
-> f GetSendStatisticsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [SendDataPoint] [SendDataPoint] [SendDataPoint] [SendDataPoint]
-> Iso
     (Maybe [SendDataPoint])
     (Maybe [SendDataPoint])
     (Maybe [SendDataPoint])
     (Maybe [SendDataPoint])
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
  [SendDataPoint] [SendDataPoint] [SendDataPoint] [SendDataPoint]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Iso [SendDataPoint] [SendDataPoint] [SendDataPoint] [SendDataPoint]
Lens.coerced

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

instance Prelude.NFData GetSendStatisticsResponse where
  rnf :: GetSendStatisticsResponse -> ()
rnf GetSendStatisticsResponse' {Int
Maybe [SendDataPoint]
$sel:sendDataPoints:GetSendStatisticsResponse' :: GetSendStatisticsResponse -> Maybe [SendDataPoint]
$sel:httpStatus:GetSendStatisticsResponse' :: GetSendStatisticsResponse -> Int
sendDataPoints :: Maybe [SendDataPoint]
httpStatus :: Int
..} =
    Maybe [SendDataPoint] -> ()
forall a. NFData a => a -> ()
Prelude.rnf Maybe [SendDataPoint]
sendDataPoints
      () -> () -> ()
forall a b. a -> b -> b
`Prelude.seq` Int -> ()
forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus