{-# 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.MetricPolicyRule
-- 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.MetricPolicyRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A setting that enables metrics at the object level. Each rule contains
-- an object group and an object group name. If the policy includes the
-- MetricPolicyRules parameter, you must include at least one rule. Each
-- metric policy can include up to five rules by default. 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.
--
-- /See:/ 'newMetricPolicyRule' smart constructor.
data MetricPolicyRule = MetricPolicyRule'
  { -- | A path or file name that defines which objects to include in the group.
    -- Wildcards (*) are acceptable.
    MetricPolicyRule -> Text
objectGroup :: Prelude.Text,
    -- | A name that allows you to refer to the object group.
    MetricPolicyRule -> Text
objectGroupName :: Prelude.Text
  }
  deriving (MetricPolicyRule -> MetricPolicyRule -> Bool
(MetricPolicyRule -> MetricPolicyRule -> Bool)
-> (MetricPolicyRule -> MetricPolicyRule -> Bool)
-> Eq MetricPolicyRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricPolicyRule -> MetricPolicyRule -> Bool
$c/= :: MetricPolicyRule -> MetricPolicyRule -> Bool
== :: MetricPolicyRule -> MetricPolicyRule -> Bool
$c== :: MetricPolicyRule -> MetricPolicyRule -> Bool
Prelude.Eq, ReadPrec [MetricPolicyRule]
ReadPrec MetricPolicyRule
Int -> ReadS MetricPolicyRule
ReadS [MetricPolicyRule]
(Int -> ReadS MetricPolicyRule)
-> ReadS [MetricPolicyRule]
-> ReadPrec MetricPolicyRule
-> ReadPrec [MetricPolicyRule]
-> Read MetricPolicyRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricPolicyRule]
$creadListPrec :: ReadPrec [MetricPolicyRule]
readPrec :: ReadPrec MetricPolicyRule
$creadPrec :: ReadPrec MetricPolicyRule
readList :: ReadS [MetricPolicyRule]
$creadList :: ReadS [MetricPolicyRule]
readsPrec :: Int -> ReadS MetricPolicyRule
$creadsPrec :: Int -> ReadS MetricPolicyRule
Prelude.Read, Int -> MetricPolicyRule -> ShowS
[MetricPolicyRule] -> ShowS
MetricPolicyRule -> String
(Int -> MetricPolicyRule -> ShowS)
-> (MetricPolicyRule -> String)
-> ([MetricPolicyRule] -> ShowS)
-> Show MetricPolicyRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricPolicyRule] -> ShowS
$cshowList :: [MetricPolicyRule] -> ShowS
show :: MetricPolicyRule -> String
$cshow :: MetricPolicyRule -> String
showsPrec :: Int -> MetricPolicyRule -> ShowS
$cshowsPrec :: Int -> MetricPolicyRule -> ShowS
Prelude.Show, (forall x. MetricPolicyRule -> Rep MetricPolicyRule x)
-> (forall x. Rep MetricPolicyRule x -> MetricPolicyRule)
-> Generic MetricPolicyRule
forall x. Rep MetricPolicyRule x -> MetricPolicyRule
forall x. MetricPolicyRule -> Rep MetricPolicyRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricPolicyRule x -> MetricPolicyRule
$cfrom :: forall x. MetricPolicyRule -> Rep MetricPolicyRule x
Prelude.Generic)

-- |
-- Create a value of 'MetricPolicyRule' 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:
--
-- 'objectGroup', 'metricPolicyRule_objectGroup' - A path or file name that defines which objects to include in the group.
-- Wildcards (*) are acceptable.
--
-- 'objectGroupName', 'metricPolicyRule_objectGroupName' - A name that allows you to refer to the object group.
newMetricPolicyRule ::
  -- | 'objectGroup'
  Prelude.Text ->
  -- | 'objectGroupName'
  Prelude.Text ->
  MetricPolicyRule
newMetricPolicyRule :: Text -> Text -> MetricPolicyRule
newMetricPolicyRule Text
pObjectGroup_ Text
pObjectGroupName_ =
  MetricPolicyRule' :: Text -> Text -> MetricPolicyRule
MetricPolicyRule'
    { $sel:objectGroup:MetricPolicyRule' :: Text
objectGroup = Text
pObjectGroup_,
      $sel:objectGroupName:MetricPolicyRule' :: Text
objectGroupName = Text
pObjectGroupName_
    }

-- | A path or file name that defines which objects to include in the group.
-- Wildcards (*) are acceptable.
metricPolicyRule_objectGroup :: Lens.Lens' MetricPolicyRule Prelude.Text
metricPolicyRule_objectGroup :: (Text -> f Text) -> MetricPolicyRule -> f MetricPolicyRule
metricPolicyRule_objectGroup = (MetricPolicyRule -> Text)
-> (MetricPolicyRule -> Text -> MetricPolicyRule)
-> Lens MetricPolicyRule MetricPolicyRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricPolicyRule' {Text
objectGroup :: Text
$sel:objectGroup:MetricPolicyRule' :: MetricPolicyRule -> Text
objectGroup} -> Text
objectGroup) (\s :: MetricPolicyRule
s@MetricPolicyRule' {} Text
a -> MetricPolicyRule
s {$sel:objectGroup:MetricPolicyRule' :: Text
objectGroup = Text
a} :: MetricPolicyRule)

-- | A name that allows you to refer to the object group.
metricPolicyRule_objectGroupName :: Lens.Lens' MetricPolicyRule Prelude.Text
metricPolicyRule_objectGroupName :: (Text -> f Text) -> MetricPolicyRule -> f MetricPolicyRule
metricPolicyRule_objectGroupName = (MetricPolicyRule -> Text)
-> (MetricPolicyRule -> Text -> MetricPolicyRule)
-> Lens MetricPolicyRule MetricPolicyRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricPolicyRule' {Text
objectGroupName :: Text
$sel:objectGroupName:MetricPolicyRule' :: MetricPolicyRule -> Text
objectGroupName} -> Text
objectGroupName) (\s :: MetricPolicyRule
s@MetricPolicyRule' {} Text
a -> MetricPolicyRule
s {$sel:objectGroupName:MetricPolicyRule' :: Text
objectGroupName = Text
a} :: MetricPolicyRule)

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

instance Prelude.Hashable MetricPolicyRule

instance Prelude.NFData MetricPolicyRule

instance Core.ToJSON MetricPolicyRule where
  toJSON :: MetricPolicyRule -> Value
toJSON MetricPolicyRule' {Text
objectGroupName :: Text
objectGroup :: Text
$sel:objectGroupName:MetricPolicyRule' :: MetricPolicyRule -> Text
$sel:objectGroup:MetricPolicyRule' :: MetricPolicyRule -> 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
"ObjectGroup" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
objectGroup),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ObjectGroupName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
objectGroupName)
          ]
      )