{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.MetricPolicy
-- 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)
module Amazonka.MediaStore.Types.MetricPolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MediaStore.Types.ContainerLevelMetrics
import Amazonka.MediaStore.Types.MetricPolicyRule
import qualified Amazonka.Prelude as Prelude

-- | The metric policy that is associated with the container. A metric policy
-- allows AWS Elemental MediaStore to send metrics to Amazon CloudWatch. In
-- the policy, you must indicate whether you want MediaStore to send
-- container-level metrics. You can also include rules to define groups of
-- objects that you want MediaStore to send object-level metrics for.
--
-- To view examples of how to construct a metric policy for your use case,
-- see
-- <https://docs.aws.amazon.com/mediastore/latest/ug/policies-metric-examples.html Example Metric Policies>.
--
-- /See:/ 'newMetricPolicy' smart constructor.
data MetricPolicy = MetricPolicy'
  { -- | A parameter that holds an array of rules that enable metrics at the
    -- object level. This parameter is optional, but if you choose to include
    -- it, you must also include at least one rule. By default, you can include
    -- up to five rules. You can also
    -- <https://console.aws.amazon.com/servicequotas/home?region=us-east-1#!/services/mediastore/quotas request a quota increase>
    -- to allow up to 300 rules per policy.
    MetricPolicy -> Maybe (NonEmpty MetricPolicyRule)
metricPolicyRules :: Prelude.Maybe (Prelude.NonEmpty MetricPolicyRule),
    -- | A setting to enable or disable metrics at the container level.
    MetricPolicy -> ContainerLevelMetrics
containerLevelMetrics :: ContainerLevelMetrics
  }
  deriving (MetricPolicy -> MetricPolicy -> Bool
(MetricPolicy -> MetricPolicy -> Bool)
-> (MetricPolicy -> MetricPolicy -> Bool) -> Eq MetricPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricPolicy -> MetricPolicy -> Bool
$c/= :: MetricPolicy -> MetricPolicy -> Bool
== :: MetricPolicy -> MetricPolicy -> Bool
$c== :: MetricPolicy -> MetricPolicy -> Bool
Prelude.Eq, ReadPrec [MetricPolicy]
ReadPrec MetricPolicy
Int -> ReadS MetricPolicy
ReadS [MetricPolicy]
(Int -> ReadS MetricPolicy)
-> ReadS [MetricPolicy]
-> ReadPrec MetricPolicy
-> ReadPrec [MetricPolicy]
-> Read MetricPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricPolicy]
$creadListPrec :: ReadPrec [MetricPolicy]
readPrec :: ReadPrec MetricPolicy
$creadPrec :: ReadPrec MetricPolicy
readList :: ReadS [MetricPolicy]
$creadList :: ReadS [MetricPolicy]
readsPrec :: Int -> ReadS MetricPolicy
$creadsPrec :: Int -> ReadS MetricPolicy
Prelude.Read, Int -> MetricPolicy -> ShowS
[MetricPolicy] -> ShowS
MetricPolicy -> String
(Int -> MetricPolicy -> ShowS)
-> (MetricPolicy -> String)
-> ([MetricPolicy] -> ShowS)
-> Show MetricPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricPolicy] -> ShowS
$cshowList :: [MetricPolicy] -> ShowS
show :: MetricPolicy -> String
$cshow :: MetricPolicy -> String
showsPrec :: Int -> MetricPolicy -> ShowS
$cshowsPrec :: Int -> MetricPolicy -> ShowS
Prelude.Show, (forall x. MetricPolicy -> Rep MetricPolicy x)
-> (forall x. Rep MetricPolicy x -> MetricPolicy)
-> Generic MetricPolicy
forall x. Rep MetricPolicy x -> MetricPolicy
forall x. MetricPolicy -> Rep MetricPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricPolicy x -> MetricPolicy
$cfrom :: forall x. MetricPolicy -> Rep MetricPolicy x
Prelude.Generic)

-- |
-- Create a value of 'MetricPolicy' 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:
--
-- 'metricPolicyRules', 'metricPolicy_metricPolicyRules' - A parameter that holds an array of rules that enable metrics at the
-- object level. This parameter is optional, but if you choose to include
-- it, you must also include at least one rule. By default, you can include
-- up to five rules. You can also
-- <https://console.aws.amazon.com/servicequotas/home?region=us-east-1#!/services/mediastore/quotas request a quota increase>
-- to allow up to 300 rules per policy.
--
-- 'containerLevelMetrics', 'metricPolicy_containerLevelMetrics' - A setting to enable or disable metrics at the container level.
newMetricPolicy ::
  -- | 'containerLevelMetrics'
  ContainerLevelMetrics ->
  MetricPolicy
newMetricPolicy :: ContainerLevelMetrics -> MetricPolicy
newMetricPolicy ContainerLevelMetrics
pContainerLevelMetrics_ =
  MetricPolicy' :: Maybe (NonEmpty MetricPolicyRule)
-> ContainerLevelMetrics -> MetricPolicy
MetricPolicy'
    { $sel:metricPolicyRules:MetricPolicy' :: Maybe (NonEmpty MetricPolicyRule)
metricPolicyRules = Maybe (NonEmpty MetricPolicyRule)
forall a. Maybe a
Prelude.Nothing,
      $sel:containerLevelMetrics:MetricPolicy' :: ContainerLevelMetrics
containerLevelMetrics = ContainerLevelMetrics
pContainerLevelMetrics_
    }

-- | A parameter that holds an array of rules that enable metrics at the
-- object level. This parameter is optional, but if you choose to include
-- it, you must also include at least one rule. By default, you can include
-- up to five rules. You can also
-- <https://console.aws.amazon.com/servicequotas/home?region=us-east-1#!/services/mediastore/quotas request a quota increase>
-- to allow up to 300 rules per policy.
metricPolicy_metricPolicyRules :: Lens.Lens' MetricPolicy (Prelude.Maybe (Prelude.NonEmpty MetricPolicyRule))
metricPolicy_metricPolicyRules :: (Maybe (NonEmpty MetricPolicyRule)
 -> f (Maybe (NonEmpty MetricPolicyRule)))
-> MetricPolicy -> f MetricPolicy
metricPolicy_metricPolicyRules = (MetricPolicy -> Maybe (NonEmpty MetricPolicyRule))
-> (MetricPolicy
    -> Maybe (NonEmpty MetricPolicyRule) -> MetricPolicy)
-> Lens
     MetricPolicy
     MetricPolicy
     (Maybe (NonEmpty MetricPolicyRule))
     (Maybe (NonEmpty MetricPolicyRule))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricPolicy' {Maybe (NonEmpty MetricPolicyRule)
metricPolicyRules :: Maybe (NonEmpty MetricPolicyRule)
$sel:metricPolicyRules:MetricPolicy' :: MetricPolicy -> Maybe (NonEmpty MetricPolicyRule)
metricPolicyRules} -> Maybe (NonEmpty MetricPolicyRule)
metricPolicyRules) (\s :: MetricPolicy
s@MetricPolicy' {} Maybe (NonEmpty MetricPolicyRule)
a -> MetricPolicy
s {$sel:metricPolicyRules:MetricPolicy' :: Maybe (NonEmpty MetricPolicyRule)
metricPolicyRules = Maybe (NonEmpty MetricPolicyRule)
a} :: MetricPolicy) ((Maybe (NonEmpty MetricPolicyRule)
  -> f (Maybe (NonEmpty MetricPolicyRule)))
 -> MetricPolicy -> f MetricPolicy)
-> ((Maybe (NonEmpty MetricPolicyRule)
     -> f (Maybe (NonEmpty MetricPolicyRule)))
    -> Maybe (NonEmpty MetricPolicyRule)
    -> f (Maybe (NonEmpty MetricPolicyRule)))
-> (Maybe (NonEmpty MetricPolicyRule)
    -> f (Maybe (NonEmpty MetricPolicyRule)))
-> MetricPolicy
-> f MetricPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty MetricPolicyRule)
  (NonEmpty MetricPolicyRule)
  (NonEmpty MetricPolicyRule)
  (NonEmpty MetricPolicyRule)
-> Iso
     (Maybe (NonEmpty MetricPolicyRule))
     (Maybe (NonEmpty MetricPolicyRule))
     (Maybe (NonEmpty MetricPolicyRule))
     (Maybe (NonEmpty MetricPolicyRule))
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
  (NonEmpty MetricPolicyRule)
  (NonEmpty MetricPolicyRule)
  (NonEmpty MetricPolicyRule)
  (NonEmpty MetricPolicyRule)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A setting to enable or disable metrics at the container level.
metricPolicy_containerLevelMetrics :: Lens.Lens' MetricPolicy ContainerLevelMetrics
metricPolicy_containerLevelMetrics :: (ContainerLevelMetrics -> f ContainerLevelMetrics)
-> MetricPolicy -> f MetricPolicy
metricPolicy_containerLevelMetrics = (MetricPolicy -> ContainerLevelMetrics)
-> (MetricPolicy -> ContainerLevelMetrics -> MetricPolicy)
-> Lens
     MetricPolicy
     MetricPolicy
     ContainerLevelMetrics
     ContainerLevelMetrics
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricPolicy' {ContainerLevelMetrics
containerLevelMetrics :: ContainerLevelMetrics
$sel:containerLevelMetrics:MetricPolicy' :: MetricPolicy -> ContainerLevelMetrics
containerLevelMetrics} -> ContainerLevelMetrics
containerLevelMetrics) (\s :: MetricPolicy
s@MetricPolicy' {} ContainerLevelMetrics
a -> MetricPolicy
s {$sel:containerLevelMetrics:MetricPolicy' :: ContainerLevelMetrics
containerLevelMetrics = ContainerLevelMetrics
a} :: MetricPolicy)

instance Core.FromJSON MetricPolicy where
  parseJSON :: Value -> Parser MetricPolicy
parseJSON =
    String
-> (Object -> Parser MetricPolicy) -> Value -> Parser MetricPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MetricPolicy"
      ( \Object
x ->
          Maybe (NonEmpty MetricPolicyRule)
-> ContainerLevelMetrics -> MetricPolicy
MetricPolicy'
            (Maybe (NonEmpty MetricPolicyRule)
 -> ContainerLevelMetrics -> MetricPolicy)
-> Parser (Maybe (NonEmpty MetricPolicyRule))
-> Parser (ContainerLevelMetrics -> MetricPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty MetricPolicyRule))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MetricPolicyRules")
            Parser (ContainerLevelMetrics -> MetricPolicy)
-> Parser ContainerLevelMetrics -> Parser MetricPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ContainerLevelMetrics
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ContainerLevelMetrics")
      )

instance Prelude.Hashable MetricPolicy

instance Prelude.NFData MetricPolicy

instance Core.ToJSON MetricPolicy where
  toJSON :: MetricPolicy -> Value
toJSON MetricPolicy' {Maybe (NonEmpty MetricPolicyRule)
ContainerLevelMetrics
containerLevelMetrics :: ContainerLevelMetrics
metricPolicyRules :: Maybe (NonEmpty MetricPolicyRule)
$sel:containerLevelMetrics:MetricPolicy' :: MetricPolicy -> ContainerLevelMetrics
$sel:metricPolicyRules:MetricPolicy' :: MetricPolicy -> Maybe (NonEmpty MetricPolicyRule)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MetricPolicyRules" Text -> NonEmpty MetricPolicyRule -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty MetricPolicyRule -> Pair)
-> Maybe (NonEmpty MetricPolicyRule) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty MetricPolicyRule)
metricPolicyRules,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"ContainerLevelMetrics"
                  Text -> ContainerLevelMetrics -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ContainerLevelMetrics
containerLevelMetrics
              )
          ]
      )