{-# 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.Pinpoint.Types.MetricDimension
-- 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.Pinpoint.Types.MetricDimension where

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

-- | Specifies metric-based criteria for including or excluding endpoints
-- from a segment. These criteria derive from custom metrics that you
-- define for endpoints.
--
-- /See:/ 'newMetricDimension' smart constructor.
data MetricDimension = MetricDimension'
  { -- | The operator to use when comparing metric values. Valid values are:
    -- GREATER_THAN, LESS_THAN, GREATER_THAN_OR_EQUAL, LESS_THAN_OR_EQUAL, and
    -- EQUAL.
    MetricDimension -> Text
comparisonOperator :: Prelude.Text,
    -- | The value to compare.
    MetricDimension -> Double
value :: Prelude.Double
  }
  deriving (MetricDimension -> MetricDimension -> Bool
(MetricDimension -> MetricDimension -> Bool)
-> (MetricDimension -> MetricDimension -> Bool)
-> Eq MetricDimension
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricDimension -> MetricDimension -> Bool
$c/= :: MetricDimension -> MetricDimension -> Bool
== :: MetricDimension -> MetricDimension -> Bool
$c== :: MetricDimension -> MetricDimension -> Bool
Prelude.Eq, ReadPrec [MetricDimension]
ReadPrec MetricDimension
Int -> ReadS MetricDimension
ReadS [MetricDimension]
(Int -> ReadS MetricDimension)
-> ReadS [MetricDimension]
-> ReadPrec MetricDimension
-> ReadPrec [MetricDimension]
-> Read MetricDimension
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricDimension]
$creadListPrec :: ReadPrec [MetricDimension]
readPrec :: ReadPrec MetricDimension
$creadPrec :: ReadPrec MetricDimension
readList :: ReadS [MetricDimension]
$creadList :: ReadS [MetricDimension]
readsPrec :: Int -> ReadS MetricDimension
$creadsPrec :: Int -> ReadS MetricDimension
Prelude.Read, Int -> MetricDimension -> ShowS
[MetricDimension] -> ShowS
MetricDimension -> String
(Int -> MetricDimension -> ShowS)
-> (MetricDimension -> String)
-> ([MetricDimension] -> ShowS)
-> Show MetricDimension
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricDimension] -> ShowS
$cshowList :: [MetricDimension] -> ShowS
show :: MetricDimension -> String
$cshow :: MetricDimension -> String
showsPrec :: Int -> MetricDimension -> ShowS
$cshowsPrec :: Int -> MetricDimension -> ShowS
Prelude.Show, (forall x. MetricDimension -> Rep MetricDimension x)
-> (forall x. Rep MetricDimension x -> MetricDimension)
-> Generic MetricDimension
forall x. Rep MetricDimension x -> MetricDimension
forall x. MetricDimension -> Rep MetricDimension x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricDimension x -> MetricDimension
$cfrom :: forall x. MetricDimension -> Rep MetricDimension x
Prelude.Generic)

-- |
-- Create a value of 'MetricDimension' 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:
--
-- 'comparisonOperator', 'metricDimension_comparisonOperator' - The operator to use when comparing metric values. Valid values are:
-- GREATER_THAN, LESS_THAN, GREATER_THAN_OR_EQUAL, LESS_THAN_OR_EQUAL, and
-- EQUAL.
--
-- 'value', 'metricDimension_value' - The value to compare.
newMetricDimension ::
  -- | 'comparisonOperator'
  Prelude.Text ->
  -- | 'value'
  Prelude.Double ->
  MetricDimension
newMetricDimension :: Text -> Double -> MetricDimension
newMetricDimension Text
pComparisonOperator_ Double
pValue_ =
  MetricDimension' :: Text -> Double -> MetricDimension
MetricDimension'
    { $sel:comparisonOperator:MetricDimension' :: Text
comparisonOperator =
        Text
pComparisonOperator_,
      $sel:value:MetricDimension' :: Double
value = Double
pValue_
    }

-- | The operator to use when comparing metric values. Valid values are:
-- GREATER_THAN, LESS_THAN, GREATER_THAN_OR_EQUAL, LESS_THAN_OR_EQUAL, and
-- EQUAL.
metricDimension_comparisonOperator :: Lens.Lens' MetricDimension Prelude.Text
metricDimension_comparisonOperator :: (Text -> f Text) -> MetricDimension -> f MetricDimension
metricDimension_comparisonOperator = (MetricDimension -> Text)
-> (MetricDimension -> Text -> MetricDimension)
-> Lens MetricDimension MetricDimension Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDimension' {Text
comparisonOperator :: Text
$sel:comparisonOperator:MetricDimension' :: MetricDimension -> Text
comparisonOperator} -> Text
comparisonOperator) (\s :: MetricDimension
s@MetricDimension' {} Text
a -> MetricDimension
s {$sel:comparisonOperator:MetricDimension' :: Text
comparisonOperator = Text
a} :: MetricDimension)

-- | The value to compare.
metricDimension_value :: Lens.Lens' MetricDimension Prelude.Double
metricDimension_value :: (Double -> f Double) -> MetricDimension -> f MetricDimension
metricDimension_value = (MetricDimension -> Double)
-> (MetricDimension -> Double -> MetricDimension)
-> Lens MetricDimension MetricDimension Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDimension' {Double
value :: Double
$sel:value:MetricDimension' :: MetricDimension -> Double
value} -> Double
value) (\s :: MetricDimension
s@MetricDimension' {} Double
a -> MetricDimension
s {$sel:value:MetricDimension' :: Double
value = Double
a} :: MetricDimension)

instance Core.FromJSON MetricDimension where
  parseJSON :: Value -> Parser MetricDimension
parseJSON =
    String
-> (Object -> Parser MetricDimension)
-> Value
-> Parser MetricDimension
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MetricDimension"
      ( \Object
x ->
          Text -> Double -> MetricDimension
MetricDimension'
            (Text -> Double -> MetricDimension)
-> Parser Text -> Parser (Double -> MetricDimension)
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
"ComparisonOperator")
            Parser (Double -> MetricDimension)
-> Parser Double -> Parser MetricDimension
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Value")
      )

instance Prelude.Hashable MetricDimension

instance Prelude.NFData MetricDimension

instance Core.ToJSON MetricDimension where
  toJSON :: MetricDimension -> Value
toJSON MetricDimension' {Double
Text
value :: Double
comparisonOperator :: Text
$sel:value:MetricDimension' :: MetricDimension -> Double
$sel:comparisonOperator:MetricDimension' :: MetricDimension -> 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
"ComparisonOperator" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
comparisonOperator),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Double
value)
          ]
      )