{-# 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.MediaStore.PutMetricPolicy
-- 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)
--
-- The metric policy that you want to add to the container. A metric policy
-- allows AWS Elemental MediaStore to send metrics to Amazon CloudWatch. It
-- takes up to 20 minutes for the new policy to take effect.
module Amazonka.MediaStore.PutMetricPolicy
  ( -- * Creating a Request
    PutMetricPolicy (..),
    newPutMetricPolicy,

    -- * Request Lenses
    putMetricPolicy_containerName,
    putMetricPolicy_metricPolicy,

    -- * Destructuring the Response
    PutMetricPolicyResponse (..),
    newPutMetricPolicyResponse,

    -- * Response Lenses
    putMetricPolicyResponse_httpStatus,
  )
where

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

-- | /See:/ 'newPutMetricPolicy' smart constructor.
data PutMetricPolicy = PutMetricPolicy'
  { -- | The name of the container that you want to add the metric policy to.
    PutMetricPolicy -> Text
containerName :: Prelude.Text,
    -- | The metric policy that you want to associate with the container. In the
    -- policy, you must indicate whether you want MediaStore to send
    -- container-level metrics. You can also include up to five rules to define
    -- groups of objects that you want MediaStore to send object-level metrics
    -- for. If you include rules in the policy, construct each rule with both
    -- of the following:
    --
    -- -   An object group that defines which objects to include in the group.
    --     The definition can be a path or a file name, but it can\'t have more
    --     than 900 characters. Valid characters are: a-z, A-Z, 0-9, _
    --     (underscore), = (equal), : (colon), . (period), - (hyphen), ~
    --     (tilde), \/ (forward slash), and * (asterisk). Wildcards (*) are
    --     acceptable.
    --
    -- -   An object group name that allows you to refer to the object group.
    --     The name can\'t have more than 30 characters. Valid characters are:
    --     a-z, A-Z, 0-9, and _ (underscore).
    PutMetricPolicy -> MetricPolicy
metricPolicy :: MetricPolicy
  }
  deriving (PutMetricPolicy -> PutMetricPolicy -> Bool
(PutMetricPolicy -> PutMetricPolicy -> Bool)
-> (PutMetricPolicy -> PutMetricPolicy -> Bool)
-> Eq PutMetricPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutMetricPolicy -> PutMetricPolicy -> Bool
$c/= :: PutMetricPolicy -> PutMetricPolicy -> Bool
== :: PutMetricPolicy -> PutMetricPolicy -> Bool
$c== :: PutMetricPolicy -> PutMetricPolicy -> Bool
Prelude.Eq, ReadPrec [PutMetricPolicy]
ReadPrec PutMetricPolicy
Int -> ReadS PutMetricPolicy
ReadS [PutMetricPolicy]
(Int -> ReadS PutMetricPolicy)
-> ReadS [PutMetricPolicy]
-> ReadPrec PutMetricPolicy
-> ReadPrec [PutMetricPolicy]
-> Read PutMetricPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutMetricPolicy]
$creadListPrec :: ReadPrec [PutMetricPolicy]
readPrec :: ReadPrec PutMetricPolicy
$creadPrec :: ReadPrec PutMetricPolicy
readList :: ReadS [PutMetricPolicy]
$creadList :: ReadS [PutMetricPolicy]
readsPrec :: Int -> ReadS PutMetricPolicy
$creadsPrec :: Int -> ReadS PutMetricPolicy
Prelude.Read, Int -> PutMetricPolicy -> ShowS
[PutMetricPolicy] -> ShowS
PutMetricPolicy -> String
(Int -> PutMetricPolicy -> ShowS)
-> (PutMetricPolicy -> String)
-> ([PutMetricPolicy] -> ShowS)
-> Show PutMetricPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutMetricPolicy] -> ShowS
$cshowList :: [PutMetricPolicy] -> ShowS
show :: PutMetricPolicy -> String
$cshow :: PutMetricPolicy -> String
showsPrec :: Int -> PutMetricPolicy -> ShowS
$cshowsPrec :: Int -> PutMetricPolicy -> ShowS
Prelude.Show, (forall x. PutMetricPolicy -> Rep PutMetricPolicy x)
-> (forall x. Rep PutMetricPolicy x -> PutMetricPolicy)
-> Generic PutMetricPolicy
forall x. Rep PutMetricPolicy x -> PutMetricPolicy
forall x. PutMetricPolicy -> Rep PutMetricPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutMetricPolicy x -> PutMetricPolicy
$cfrom :: forall x. PutMetricPolicy -> Rep PutMetricPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutMetricPolicy' 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:
--
-- 'containerName', 'putMetricPolicy_containerName' - The name of the container that you want to add the metric policy to.
--
-- 'metricPolicy', 'putMetricPolicy_metricPolicy' - The metric policy that you want to associate with the container. In the
-- policy, you must indicate whether you want MediaStore to send
-- container-level metrics. You can also include up to five rules to define
-- groups of objects that you want MediaStore to send object-level metrics
-- for. If you include rules in the policy, construct each rule with both
-- of the following:
--
-- -   An object group that defines which objects to include in the group.
--     The definition can be a path or a file name, but it can\'t have more
--     than 900 characters. Valid characters are: a-z, A-Z, 0-9, _
--     (underscore), = (equal), : (colon), . (period), - (hyphen), ~
--     (tilde), \/ (forward slash), and * (asterisk). Wildcards (*) are
--     acceptable.
--
-- -   An object group name that allows you to refer to the object group.
--     The name can\'t have more than 30 characters. Valid characters are:
--     a-z, A-Z, 0-9, and _ (underscore).
newPutMetricPolicy ::
  -- | 'containerName'
  Prelude.Text ->
  -- | 'metricPolicy'
  MetricPolicy ->
  PutMetricPolicy
newPutMetricPolicy :: Text -> MetricPolicy -> PutMetricPolicy
newPutMetricPolicy Text
pContainerName_ MetricPolicy
pMetricPolicy_ =
  PutMetricPolicy' :: Text -> MetricPolicy -> PutMetricPolicy
PutMetricPolicy'
    { $sel:containerName:PutMetricPolicy' :: Text
containerName = Text
pContainerName_,
      $sel:metricPolicy:PutMetricPolicy' :: MetricPolicy
metricPolicy = MetricPolicy
pMetricPolicy_
    }

-- | The name of the container that you want to add the metric policy to.
putMetricPolicy_containerName :: Lens.Lens' PutMetricPolicy Prelude.Text
putMetricPolicy_containerName :: (Text -> f Text) -> PutMetricPolicy -> f PutMetricPolicy
putMetricPolicy_containerName = (PutMetricPolicy -> Text)
-> (PutMetricPolicy -> Text -> PutMetricPolicy)
-> Lens PutMetricPolicy PutMetricPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutMetricPolicy' {Text
containerName :: Text
$sel:containerName:PutMetricPolicy' :: PutMetricPolicy -> Text
containerName} -> Text
containerName) (\s :: PutMetricPolicy
s@PutMetricPolicy' {} Text
a -> PutMetricPolicy
s {$sel:containerName:PutMetricPolicy' :: Text
containerName = Text
a} :: PutMetricPolicy)

-- | The metric policy that you want to associate with the container. In the
-- policy, you must indicate whether you want MediaStore to send
-- container-level metrics. You can also include up to five rules to define
-- groups of objects that you want MediaStore to send object-level metrics
-- for. If you include rules in the policy, construct each rule with both
-- of the following:
--
-- -   An object group that defines which objects to include in the group.
--     The definition can be a path or a file name, but it can\'t have more
--     than 900 characters. Valid characters are: a-z, A-Z, 0-9, _
--     (underscore), = (equal), : (colon), . (period), - (hyphen), ~
--     (tilde), \/ (forward slash), and * (asterisk). Wildcards (*) are
--     acceptable.
--
-- -   An object group name that allows you to refer to the object group.
--     The name can\'t have more than 30 characters. Valid characters are:
--     a-z, A-Z, 0-9, and _ (underscore).
putMetricPolicy_metricPolicy :: Lens.Lens' PutMetricPolicy MetricPolicy
putMetricPolicy_metricPolicy :: (MetricPolicy -> f MetricPolicy)
-> PutMetricPolicy -> f PutMetricPolicy
putMetricPolicy_metricPolicy = (PutMetricPolicy -> MetricPolicy)
-> (PutMetricPolicy -> MetricPolicy -> PutMetricPolicy)
-> Lens PutMetricPolicy PutMetricPolicy MetricPolicy MetricPolicy
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutMetricPolicy' {MetricPolicy
metricPolicy :: MetricPolicy
$sel:metricPolicy:PutMetricPolicy' :: PutMetricPolicy -> MetricPolicy
metricPolicy} -> MetricPolicy
metricPolicy) (\s :: PutMetricPolicy
s@PutMetricPolicy' {} MetricPolicy
a -> PutMetricPolicy
s {$sel:metricPolicy:PutMetricPolicy' :: MetricPolicy
metricPolicy = MetricPolicy
a} :: PutMetricPolicy)

instance Core.AWSRequest PutMetricPolicy where
  type
    AWSResponse PutMetricPolicy =
      PutMetricPolicyResponse
  request :: PutMetricPolicy -> Request PutMetricPolicy
request = Service -> PutMetricPolicy -> Request PutMetricPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutMetricPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutMetricPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse PutMetricPolicy))
-> Logger
-> Service
-> Proxy PutMetricPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutMetricPolicy)))
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 -> PutMetricPolicyResponse
PutMetricPolicyResponse'
            (Int -> PutMetricPolicyResponse)
-> Either String Int -> Either String PutMetricPolicyResponse
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 PutMetricPolicy

instance Prelude.NFData PutMetricPolicy

instance Core.ToHeaders PutMetricPolicy where
  toHeaders :: PutMetricPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutMetricPolicy -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"MediaStore_20170901.PutMetricPolicy" ::
                          Prelude.ByteString
                      ),
            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 PutMetricPolicy where
  toJSON :: PutMetricPolicy -> Value
toJSON PutMetricPolicy' {Text
MetricPolicy
metricPolicy :: MetricPolicy
containerName :: Text
$sel:metricPolicy:PutMetricPolicy' :: PutMetricPolicy -> MetricPolicy
$sel:containerName:PutMetricPolicy' :: PutMetricPolicy -> 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
"ContainerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
containerName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MetricPolicy" Text -> MetricPolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= MetricPolicy
metricPolicy)
          ]
      )

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

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

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

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

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

instance Prelude.NFData PutMetricPolicyResponse