{-# 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-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)
--
-- An operation for publishing metrics from the customers to the Ops plane.
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.Lens as Lens
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'
  { -- | Publishes environment metric data to Amazon CloudWatch.
    PublishMetrics -> Text
environmentName :: Prelude.Text,
    -- | Publishes metric data points to Amazon CloudWatch. CloudWatch associates
    -- the data points with the specified metrica.
    PublishMetrics -> [MetricDatum]
metricData :: [MetricDatum]
  }
  deriving (PublishMetrics -> PublishMetrics -> Bool
(PublishMetrics -> PublishMetrics -> Bool)
-> (PublishMetrics -> PublishMetrics -> Bool) -> Eq PublishMetrics
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]
(Int -> ReadS PublishMetrics)
-> ReadS [PublishMetrics]
-> ReadPrec PublishMetrics
-> ReadPrec [PublishMetrics]
-> Read 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
(Int -> PublishMetrics -> ShowS)
-> (PublishMetrics -> String)
-> ([PublishMetrics] -> ShowS)
-> Show PublishMetrics
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. PublishMetrics -> Rep PublishMetrics x)
-> (forall x. Rep PublishMetrics x -> PublishMetrics)
-> Generic PublishMetrics
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' - Publishes environment metric data to Amazon CloudWatch.
--
-- 'metricData', 'publishMetrics_metricData' - Publishes metric data points to Amazon CloudWatch. CloudWatch associates
-- the data points with the specified metrica.
newPublishMetrics ::
  -- | 'environmentName'
  Prelude.Text ->
  PublishMetrics
newPublishMetrics :: Text -> PublishMetrics
newPublishMetrics Text
pEnvironmentName_ =
  PublishMetrics' :: Text -> [MetricDatum] -> PublishMetrics
PublishMetrics'
    { $sel:environmentName:PublishMetrics' :: Text
environmentName =
        Text
pEnvironmentName_,
      $sel:metricData:PublishMetrics' :: [MetricDatum]
metricData = [MetricDatum]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Publishes environment metric data to Amazon CloudWatch.
publishMetrics_environmentName :: Lens.Lens' PublishMetrics Prelude.Text
publishMetrics_environmentName :: (Text -> f Text) -> PublishMetrics -> f PublishMetrics
publishMetrics_environmentName = (PublishMetrics -> Text)
-> (PublishMetrics -> Text -> PublishMetrics)
-> Lens PublishMetrics PublishMetrics Text Text
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)

-- | Publishes metric data points to Amazon CloudWatch. CloudWatch associates
-- the data points with the specified metrica.
publishMetrics_metricData :: Lens.Lens' PublishMetrics [MetricDatum]
publishMetrics_metricData :: ([MetricDatum] -> f [MetricDatum])
-> PublishMetrics -> f PublishMetrics
publishMetrics_metricData = (PublishMetrics -> [MetricDatum])
-> (PublishMetrics -> [MetricDatum] -> PublishMetrics)
-> Lens PublishMetrics PublishMetrics [MetricDatum] [MetricDatum]
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) (([MetricDatum] -> f [MetricDatum])
 -> PublishMetrics -> f PublishMetrics)
-> (([MetricDatum] -> f [MetricDatum])
    -> [MetricDatum] -> f [MetricDatum])
-> ([MetricDatum] -> f [MetricDatum])
-> PublishMetrics
-> f PublishMetrics
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([MetricDatum] -> f [MetricDatum])
-> [MetricDatum] -> f [MetricDatum]
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 :: PublishMetrics -> Request PublishMetrics
request = Service -> PublishMetrics -> Request PublishMetrics
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PublishMetrics
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PublishMetrics)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse PublishMetrics))
-> Logger
-> Service
-> Proxy PublishMetrics
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PublishMetrics)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PublishMetricsResponse
PublishMetricsResponse'
            (Int -> PublishMetricsResponse)
-> Either String Int -> Either String PublishMetricsResponse
forall (f :: * -> *) a b. Functor 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 PublishMetrics

instance Prelude.NFData PublishMetrics

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

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MetricData" Text -> [MetricDatum] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [MetricDatum]
metricData)]
      )

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

instance Core.ToQuery PublishMetrics where
  toQuery :: PublishMetrics -> QueryString
toQuery = QueryString -> PublishMetrics -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(PublishMetricsResponse -> PublishMetricsResponse -> Bool)
-> (PublishMetricsResponse -> PublishMetricsResponse -> Bool)
-> Eq PublishMetricsResponse
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]
(Int -> ReadS PublishMetricsResponse)
-> ReadS [PublishMetricsResponse]
-> ReadPrec PublishMetricsResponse
-> ReadPrec [PublishMetricsResponse]
-> Read 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
(Int -> PublishMetricsResponse -> ShowS)
-> (PublishMetricsResponse -> String)
-> ([PublishMetricsResponse] -> ShowS)
-> Show PublishMetricsResponse
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. PublishMetricsResponse -> Rep PublishMetricsResponse x)
-> (forall x.
    Rep PublishMetricsResponse x -> PublishMetricsResponse)
-> Generic PublishMetricsResponse
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' :: Int -> PublishMetricsResponse
PublishMetricsResponse' {$sel:httpStatus:PublishMetricsResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
publishMetricsResponse_httpStatus :: Lens.Lens' PublishMetricsResponse Prelude.Int
publishMetricsResponse_httpStatus :: (Int -> f Int)
-> PublishMetricsResponse -> f PublishMetricsResponse
publishMetricsResponse_httpStatus = (PublishMetricsResponse -> Int)
-> (PublishMetricsResponse -> Int -> PublishMetricsResponse)
-> Lens PublishMetricsResponse PublishMetricsResponse Int Int
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