{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.MediaStore.Types.MetricPolicyRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $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 :: Lens' MetricPolicyRule Text
metricPolicyRule_objectGroup = 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 :: Lens' MetricPolicyRule Text
metricPolicyRule_objectGroupName = 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 Data.FromJSON MetricPolicyRule where
  parseJSON :: Value -> Parser MetricPolicyRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MetricPolicyRule"
      ( \Object
x ->
          Text -> Text -> MetricPolicyRule
MetricPolicyRule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ObjectGroup")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ObjectGroupName")
      )

instance Prelude.Hashable MetricPolicyRule where
  hashWithSalt :: Int -> MetricPolicyRule -> Int
hashWithSalt Int
_salt MetricPolicyRule' {Text
objectGroupName :: Text
objectGroup :: Text
$sel:objectGroupName:MetricPolicyRule' :: MetricPolicyRule -> Text
$sel:objectGroup:MetricPolicyRule' :: MetricPolicyRule -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
objectGroup
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
objectGroupName

instance Prelude.NFData MetricPolicyRule where
  rnf :: MetricPolicyRule -> ()
rnf MetricPolicyRule' {Text
objectGroupName :: Text
objectGroup :: Text
$sel:objectGroupName:MetricPolicyRule' :: MetricPolicyRule -> Text
$sel:objectGroup:MetricPolicyRule' :: MetricPolicyRule -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
objectGroup
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
objectGroupName

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"ObjectGroup" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
objectGroup),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ObjectGroupName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
objectGroupName)
          ]
      )