{-# 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.CloudWatch.Types.Dimension
-- 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.CloudWatch.Types.Dimension where

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

-- | A dimension is a name\/value pair that is part of the identity of a
-- metric. You can assign up to 10 dimensions to a metric. Because
-- dimensions are part of the unique identifier for a metric, whenever you
-- add a unique name\/value pair to one of your metrics, you are creating a
-- new variation of that metric.
--
-- /See:/ 'newDimension' smart constructor.
data Dimension = Dimension'
  { -- | The name of the dimension. Dimension names must contain only ASCII
    -- characters and must include at least one non-whitespace character.
    Dimension -> Text
name :: Prelude.Text,
    -- | The value of the dimension. Dimension values must contain only ASCII
    -- characters and must include at least one non-whitespace character.
    Dimension -> Text
value :: Prelude.Text
  }
  deriving (Dimension -> Dimension -> Bool
(Dimension -> Dimension -> Bool)
-> (Dimension -> Dimension -> Bool) -> Eq Dimension
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Dimension -> Dimension -> Bool
$c/= :: Dimension -> Dimension -> Bool
== :: Dimension -> Dimension -> Bool
$c== :: Dimension -> Dimension -> Bool
Prelude.Eq, ReadPrec [Dimension]
ReadPrec Dimension
Int -> ReadS Dimension
ReadS [Dimension]
(Int -> ReadS Dimension)
-> ReadS [Dimension]
-> ReadPrec Dimension
-> ReadPrec [Dimension]
-> Read Dimension
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Dimension]
$creadListPrec :: ReadPrec [Dimension]
readPrec :: ReadPrec Dimension
$creadPrec :: ReadPrec Dimension
readList :: ReadS [Dimension]
$creadList :: ReadS [Dimension]
readsPrec :: Int -> ReadS Dimension
$creadsPrec :: Int -> ReadS Dimension
Prelude.Read, Int -> Dimension -> ShowS
[Dimension] -> ShowS
Dimension -> String
(Int -> Dimension -> ShowS)
-> (Dimension -> String)
-> ([Dimension] -> ShowS)
-> Show Dimension
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Dimension] -> ShowS
$cshowList :: [Dimension] -> ShowS
show :: Dimension -> String
$cshow :: Dimension -> String
showsPrec :: Int -> Dimension -> ShowS
$cshowsPrec :: Int -> Dimension -> ShowS
Prelude.Show, (forall x. Dimension -> Rep Dimension x)
-> (forall x. Rep Dimension x -> Dimension) -> Generic Dimension
forall x. Rep Dimension x -> Dimension
forall x. Dimension -> Rep Dimension x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Dimension x -> Dimension
$cfrom :: forall x. Dimension -> Rep Dimension x
Prelude.Generic)

-- |
-- Create a value of 'Dimension' 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:
--
-- 'name', 'dimension_name' - The name of the dimension. Dimension names must contain only ASCII
-- characters and must include at least one non-whitespace character.
--
-- 'value', 'dimension_value' - The value of the dimension. Dimension values must contain only ASCII
-- characters and must include at least one non-whitespace character.
newDimension ::
  -- | 'name'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  Dimension
newDimension :: Text -> Text -> Dimension
newDimension Text
pName_ Text
pValue_ =
  Dimension' :: Text -> Text -> Dimension
Dimension' {$sel:name:Dimension' :: Text
name = Text
pName_, $sel:value:Dimension' :: Text
value = Text
pValue_}

-- | The name of the dimension. Dimension names must contain only ASCII
-- characters and must include at least one non-whitespace character.
dimension_name :: Lens.Lens' Dimension Prelude.Text
dimension_name :: (Text -> f Text) -> Dimension -> f Dimension
dimension_name = (Dimension -> Text)
-> (Dimension -> Text -> Dimension)
-> Lens Dimension Dimension Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Dimension' {Text
name :: Text
$sel:name:Dimension' :: Dimension -> Text
name} -> Text
name) (\s :: Dimension
s@Dimension' {} Text
a -> Dimension
s {$sel:name:Dimension' :: Text
name = Text
a} :: Dimension)

-- | The value of the dimension. Dimension values must contain only ASCII
-- characters and must include at least one non-whitespace character.
dimension_value :: Lens.Lens' Dimension Prelude.Text
dimension_value :: (Text -> f Text) -> Dimension -> f Dimension
dimension_value = (Dimension -> Text)
-> (Dimension -> Text -> Dimension)
-> Lens Dimension Dimension Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Dimension' {Text
value :: Text
$sel:value:Dimension' :: Dimension -> Text
value} -> Text
value) (\s :: Dimension
s@Dimension' {} Text
a -> Dimension
s {$sel:value:Dimension' :: Text
value = Text
a} :: Dimension)

instance Core.FromXML Dimension where
  parseXML :: [Node] -> Either String Dimension
parseXML [Node]
x =
    Text -> Text -> Dimension
Dimension'
      (Text -> Text -> Dimension)
-> Either String Text -> Either String (Text -> Dimension)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Name") Either String (Text -> Dimension)
-> Either String Text -> Either String Dimension
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Value")

instance Prelude.Hashable Dimension

instance Prelude.NFData Dimension

instance Core.ToQuery Dimension where
  toQuery :: Dimension -> QueryString
toQuery Dimension' {Text
value :: Text
name :: Text
$sel:value:Dimension' :: Dimension -> Text
$sel:name:Dimension' :: Dimension -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"Name" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
name, ByteString
"Value" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
value]