{-# 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.MwAA.PublishMetrics
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- __Internal only__. Publishes environment health metrics to Amazon
-- CloudWatch.
module Amazonka.MwAA.PublishMetrics
  ( -- * Creating a Request
    PublishMetrics (..),
    newPublishMetrics,

    -- * Request Lenses
    publishMetrics_environmentName,
    publishMetrics_metricData,

    -- * Destructuring the Response
    PublishMetricsResponse (..),
    newPublishMetricsResponse,

    -- * Response Lenses
    publishMetricsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.MwAA.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newPublishMetrics' smart constructor.
data PublishMetrics = PublishMetrics'
  { -- | __Internal only__. The name of the environment.
    PublishMetrics -> Text
environmentName :: Prelude.Text,
    -- | __Internal only__. Publishes metrics to Amazon CloudWatch. To learn more
    -- about the metrics published to Amazon CloudWatch, see
    -- <https://docs.aws.amazon.com/mwaa/latest/userguide/cw-metrics.html Amazon MWAA performance metrics in Amazon CloudWatch>.
    PublishMetrics -> [MetricDatum]
metricData :: [MetricDatum]
  }
  deriving (PublishMetrics -> PublishMetrics -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PublishMetrics -> PublishMetrics -> Bool
$c/= :: PublishMetrics -> PublishMetrics -> Bool
== :: PublishMetrics -> PublishMetrics -> Bool
$c== :: PublishMetrics -> PublishMetrics -> Bool
Prelude.Eq, ReadPrec [PublishMetrics]
ReadPrec PublishMetrics
Int -> ReadS PublishMetrics
ReadS [PublishMetrics]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PublishMetrics]
$creadListPrec :: ReadPrec [PublishMetrics]
readPrec :: ReadPrec PublishMetrics
$creadPrec :: ReadPrec PublishMetrics
readList :: ReadS [PublishMetrics]
$creadList :: ReadS [PublishMetrics]
readsPrec :: Int -> ReadS PublishMetrics
$creadsPrec :: Int -> ReadS PublishMetrics
Prelude.Read, Int -> PublishMetrics -> ShowS
[PublishMetrics] -> ShowS
PublishMetrics -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PublishMetrics] -> ShowS
$cshowList :: [PublishMetrics] -> ShowS
show :: PublishMetrics -> String
$cshow :: PublishMetrics -> String
showsPrec :: Int -> PublishMetrics -> ShowS
$cshowsPrec :: Int -> PublishMetrics -> ShowS
Prelude.Show, forall x. Rep PublishMetrics x -> PublishMetrics
forall x. PublishMetrics -> Rep PublishMetrics x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PublishMetrics x -> PublishMetrics
$cfrom :: forall x. PublishMetrics -> Rep PublishMetrics x
Prelude.Generic)

-- |
-- Create a value of 'PublishMetrics' 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:
--
-- 'environmentName', 'publishMetrics_environmentName' - __Internal only__. The name of the environment.
--
-- 'metricData', 'publishMetrics_metricData' - __Internal only__. Publishes metrics to Amazon CloudWatch. To learn more
-- about the metrics published to Amazon CloudWatch, see
-- <https://docs.aws.amazon.com/mwaa/latest/userguide/cw-metrics.html Amazon MWAA performance metrics in Amazon CloudWatch>.
newPublishMetrics ::
  -- | 'environmentName'
  Prelude.Text ->
  PublishMetrics
newPublishMetrics :: Text -> PublishMetrics
newPublishMetrics Text
pEnvironmentName_ =
  PublishMetrics'
    { $sel:environmentName:PublishMetrics' :: Text
environmentName =
        Text
pEnvironmentName_,
      $sel:metricData:PublishMetrics' :: [MetricDatum]
metricData = forall a. Monoid a => a
Prelude.mempty
    }

-- | __Internal only__. The name of the environment.
publishMetrics_environmentName :: Lens.Lens' PublishMetrics Prelude.Text
publishMetrics_environmentName :: Lens' PublishMetrics Text
publishMetrics_environmentName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishMetrics' {Text
environmentName :: Text
$sel:environmentName:PublishMetrics' :: PublishMetrics -> Text
environmentName} -> Text
environmentName) (\s :: PublishMetrics
s@PublishMetrics' {} Text
a -> PublishMetrics
s {$sel:environmentName:PublishMetrics' :: Text
environmentName = Text
a} :: PublishMetrics)

-- | __Internal only__. Publishes metrics to Amazon CloudWatch. To learn more
-- about the metrics published to Amazon CloudWatch, see
-- <https://docs.aws.amazon.com/mwaa/latest/userguide/cw-metrics.html Amazon MWAA performance metrics in Amazon CloudWatch>.
publishMetrics_metricData :: Lens.Lens' PublishMetrics [MetricDatum]
publishMetrics_metricData :: Lens' PublishMetrics [MetricDatum]
publishMetrics_metricData = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishMetrics' {[MetricDatum]
metricData :: [MetricDatum]
$sel:metricData:PublishMetrics' :: PublishMetrics -> [MetricDatum]
metricData} -> [MetricDatum]
metricData) (\s :: PublishMetrics
s@PublishMetrics' {} [MetricDatum]
a -> PublishMetrics
s {$sel:metricData:PublishMetrics' :: [MetricDatum]
metricData = [MetricDatum]
a} :: PublishMetrics) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PublishMetrics where
  type
    AWSResponse PublishMetrics =
      PublishMetricsResponse
  request :: (Service -> Service) -> PublishMetrics -> Request PublishMetrics
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PublishMetrics
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PublishMetrics)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PublishMetricsResponse
PublishMetricsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PublishMetrics where
  hashWithSalt :: Int -> PublishMetrics -> Int
hashWithSalt Int
_salt PublishMetrics' {[MetricDatum]
Text
metricData :: [MetricDatum]
environmentName :: Text
$sel:metricData:PublishMetrics' :: PublishMetrics -> [MetricDatum]
$sel:environmentName:PublishMetrics' :: PublishMetrics -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
environmentName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [MetricDatum]
metricData

instance Prelude.NFData PublishMetrics where
  rnf :: PublishMetrics -> ()
rnf PublishMetrics' {[MetricDatum]
Text
metricData :: [MetricDatum]
environmentName :: Text
$sel:metricData:PublishMetrics' :: PublishMetrics -> [MetricDatum]
$sel:environmentName:PublishMetrics' :: PublishMetrics -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
environmentName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [MetricDatum]
metricData

instance Data.ToHeaders PublishMetrics where
  toHeaders :: PublishMetrics -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON PublishMetrics where
  toJSON :: PublishMetrics -> Value
toJSON PublishMetrics' {[MetricDatum]
Text
metricData :: [MetricDatum]
environmentName :: Text
$sel:metricData:PublishMetrics' :: PublishMetrics -> [MetricDatum]
$sel:environmentName:PublishMetrics' :: PublishMetrics -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"MetricData" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [MetricDatum]
metricData)]
      )

instance Data.ToPath PublishMetrics where
  toPath :: PublishMetrics -> ByteString
toPath PublishMetrics' {[MetricDatum]
Text
metricData :: [MetricDatum]
environmentName :: Text
$sel:metricData:PublishMetrics' :: PublishMetrics -> [MetricDatum]
$sel:environmentName:PublishMetrics' :: PublishMetrics -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/metrics/environments/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
environmentName]

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

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

-- |
-- Create a value of 'PublishMetricsResponse' 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:
--
-- 'httpStatus', 'publishMetricsResponse_httpStatus' - The response's http status code.
newPublishMetricsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PublishMetricsResponse
newPublishMetricsResponse :: Int -> PublishMetricsResponse
newPublishMetricsResponse Int
pHttpStatus_ =
  PublishMetricsResponse' {$sel:httpStatus:PublishMetricsResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData PublishMetricsResponse where
  rnf :: PublishMetricsResponse -> ()
rnf PublishMetricsResponse' {Int
httpStatus :: Int
$sel:httpStatus:PublishMetricsResponse' :: PublishMetricsResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus