{-# 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.AutoScaling.Types.MetricDataQuery
-- 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.AutoScaling.Types.MetricDataQuery where

import Amazonka.AutoScaling.Types.MetricStat
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

-- | The metric data to return. Also defines whether this call is returning
-- data for one metric only, or whether it is performing a math expression
-- on the values of returned metric statistics to create a new time series.
-- A time series is a series of data points, each of which is associated
-- with a timestamp.
--
-- For more information and examples, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/predictive-scaling-customized-metric-specification.html Advanced predictive scaling policy configurations using custom metrics>
-- in the /Amazon EC2 Auto Scaling User Guide/.
--
-- /See:/ 'newMetricDataQuery' smart constructor.
data MetricDataQuery = MetricDataQuery'
  { -- | The math expression to perform on the returned data, if this object is
    -- performing a math expression. This expression can use the @Id@ of the
    -- other metrics to refer to those metrics, and can also use the @Id@ of
    -- other expressions to use the result of those expressions.
    --
    -- Conditional: Within each @MetricDataQuery@ object, you must specify
    -- either @Expression@ or @MetricStat@, but not both.
    MetricDataQuery -> Maybe Text
expression :: Prelude.Maybe Prelude.Text,
    -- | A human-readable label for this metric or expression. This is especially
    -- useful if this is a math expression, so that you know what the value
    -- represents.
    MetricDataQuery -> Maybe Text
label :: Prelude.Maybe Prelude.Text,
    -- | Information about the metric data to return.
    --
    -- Conditional: Within each @MetricDataQuery@ object, you must specify
    -- either @Expression@ or @MetricStat@, but not both.
    MetricDataQuery -> Maybe MetricStat
metricStat :: Prelude.Maybe MetricStat,
    -- | Indicates whether to return the timestamps and raw data values of this
    -- metric.
    --
    -- If you use any math expressions, specify @true@ for this value for only
    -- the final math expression that the metric specification is based on. You
    -- must specify @false@ for @ReturnData@ for all the other metrics and
    -- expressions used in the metric specification.
    --
    -- If you are only retrieving metrics and not performing any math
    -- expressions, do not specify anything for @ReturnData@. This sets it to
    -- its default (@true@).
    MetricDataQuery -> Maybe Bool
returnData :: Prelude.Maybe Prelude.Bool,
    -- | A short name that identifies the object\'s results in the response. This
    -- name must be unique among all @MetricDataQuery@ objects specified for a
    -- single scaling policy. If you are performing math expressions on this
    -- set of data, this name represents that data and can serve as a variable
    -- in the mathematical expression. The valid characters are letters,
    -- numbers, and underscores. The first character must be a lowercase
    -- letter.
    MetricDataQuery -> Text
id :: Prelude.Text
  }
  deriving (MetricDataQuery -> MetricDataQuery -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricDataQuery -> MetricDataQuery -> Bool
$c/= :: MetricDataQuery -> MetricDataQuery -> Bool
== :: MetricDataQuery -> MetricDataQuery -> Bool
$c== :: MetricDataQuery -> MetricDataQuery -> Bool
Prelude.Eq, ReadPrec [MetricDataQuery]
ReadPrec MetricDataQuery
Int -> ReadS MetricDataQuery
ReadS [MetricDataQuery]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricDataQuery]
$creadListPrec :: ReadPrec [MetricDataQuery]
readPrec :: ReadPrec MetricDataQuery
$creadPrec :: ReadPrec MetricDataQuery
readList :: ReadS [MetricDataQuery]
$creadList :: ReadS [MetricDataQuery]
readsPrec :: Int -> ReadS MetricDataQuery
$creadsPrec :: Int -> ReadS MetricDataQuery
Prelude.Read, Int -> MetricDataQuery -> ShowS
[MetricDataQuery] -> ShowS
MetricDataQuery -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricDataQuery] -> ShowS
$cshowList :: [MetricDataQuery] -> ShowS
show :: MetricDataQuery -> String
$cshow :: MetricDataQuery -> String
showsPrec :: Int -> MetricDataQuery -> ShowS
$cshowsPrec :: Int -> MetricDataQuery -> ShowS
Prelude.Show, forall x. Rep MetricDataQuery x -> MetricDataQuery
forall x. MetricDataQuery -> Rep MetricDataQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricDataQuery x -> MetricDataQuery
$cfrom :: forall x. MetricDataQuery -> Rep MetricDataQuery x
Prelude.Generic)

-- |
-- Create a value of 'MetricDataQuery' 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:
--
-- 'expression', 'metricDataQuery_expression' - The math expression to perform on the returned data, if this object is
-- performing a math expression. This expression can use the @Id@ of the
-- other metrics to refer to those metrics, and can also use the @Id@ of
-- other expressions to use the result of those expressions.
--
-- Conditional: Within each @MetricDataQuery@ object, you must specify
-- either @Expression@ or @MetricStat@, but not both.
--
-- 'label', 'metricDataQuery_label' - A human-readable label for this metric or expression. This is especially
-- useful if this is a math expression, so that you know what the value
-- represents.
--
-- 'metricStat', 'metricDataQuery_metricStat' - Information about the metric data to return.
--
-- Conditional: Within each @MetricDataQuery@ object, you must specify
-- either @Expression@ or @MetricStat@, but not both.
--
-- 'returnData', 'metricDataQuery_returnData' - Indicates whether to return the timestamps and raw data values of this
-- metric.
--
-- If you use any math expressions, specify @true@ for this value for only
-- the final math expression that the metric specification is based on. You
-- must specify @false@ for @ReturnData@ for all the other metrics and
-- expressions used in the metric specification.
--
-- If you are only retrieving metrics and not performing any math
-- expressions, do not specify anything for @ReturnData@. This sets it to
-- its default (@true@).
--
-- 'id', 'metricDataQuery_id' - A short name that identifies the object\'s results in the response. This
-- name must be unique among all @MetricDataQuery@ objects specified for a
-- single scaling policy. If you are performing math expressions on this
-- set of data, this name represents that data and can serve as a variable
-- in the mathematical expression. The valid characters are letters,
-- numbers, and underscores. The first character must be a lowercase
-- letter.
newMetricDataQuery ::
  -- | 'id'
  Prelude.Text ->
  MetricDataQuery
newMetricDataQuery :: Text -> MetricDataQuery
newMetricDataQuery Text
pId_ =
  MetricDataQuery'
    { $sel:expression:MetricDataQuery' :: Maybe Text
expression = forall a. Maybe a
Prelude.Nothing,
      $sel:label:MetricDataQuery' :: Maybe Text
label = forall a. Maybe a
Prelude.Nothing,
      $sel:metricStat:MetricDataQuery' :: Maybe MetricStat
metricStat = forall a. Maybe a
Prelude.Nothing,
      $sel:returnData:MetricDataQuery' :: Maybe Bool
returnData = forall a. Maybe a
Prelude.Nothing,
      $sel:id:MetricDataQuery' :: Text
id = Text
pId_
    }

-- | The math expression to perform on the returned data, if this object is
-- performing a math expression. This expression can use the @Id@ of the
-- other metrics to refer to those metrics, and can also use the @Id@ of
-- other expressions to use the result of those expressions.
--
-- Conditional: Within each @MetricDataQuery@ object, you must specify
-- either @Expression@ or @MetricStat@, but not both.
metricDataQuery_expression :: Lens.Lens' MetricDataQuery (Prelude.Maybe Prelude.Text)
metricDataQuery_expression :: Lens' MetricDataQuery (Maybe Text)
metricDataQuery_expression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDataQuery' {Maybe Text
expression :: Maybe Text
$sel:expression:MetricDataQuery' :: MetricDataQuery -> Maybe Text
expression} -> Maybe Text
expression) (\s :: MetricDataQuery
s@MetricDataQuery' {} Maybe Text
a -> MetricDataQuery
s {$sel:expression:MetricDataQuery' :: Maybe Text
expression = Maybe Text
a} :: MetricDataQuery)

-- | A human-readable label for this metric or expression. This is especially
-- useful if this is a math expression, so that you know what the value
-- represents.
metricDataQuery_label :: Lens.Lens' MetricDataQuery (Prelude.Maybe Prelude.Text)
metricDataQuery_label :: Lens' MetricDataQuery (Maybe Text)
metricDataQuery_label = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDataQuery' {Maybe Text
label :: Maybe Text
$sel:label:MetricDataQuery' :: MetricDataQuery -> Maybe Text
label} -> Maybe Text
label) (\s :: MetricDataQuery
s@MetricDataQuery' {} Maybe Text
a -> MetricDataQuery
s {$sel:label:MetricDataQuery' :: Maybe Text
label = Maybe Text
a} :: MetricDataQuery)

-- | Information about the metric data to return.
--
-- Conditional: Within each @MetricDataQuery@ object, you must specify
-- either @Expression@ or @MetricStat@, but not both.
metricDataQuery_metricStat :: Lens.Lens' MetricDataQuery (Prelude.Maybe MetricStat)
metricDataQuery_metricStat :: Lens' MetricDataQuery (Maybe MetricStat)
metricDataQuery_metricStat = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDataQuery' {Maybe MetricStat
metricStat :: Maybe MetricStat
$sel:metricStat:MetricDataQuery' :: MetricDataQuery -> Maybe MetricStat
metricStat} -> Maybe MetricStat
metricStat) (\s :: MetricDataQuery
s@MetricDataQuery' {} Maybe MetricStat
a -> MetricDataQuery
s {$sel:metricStat:MetricDataQuery' :: Maybe MetricStat
metricStat = Maybe MetricStat
a} :: MetricDataQuery)

-- | Indicates whether to return the timestamps and raw data values of this
-- metric.
--
-- If you use any math expressions, specify @true@ for this value for only
-- the final math expression that the metric specification is based on. You
-- must specify @false@ for @ReturnData@ for all the other metrics and
-- expressions used in the metric specification.
--
-- If you are only retrieving metrics and not performing any math
-- expressions, do not specify anything for @ReturnData@. This sets it to
-- its default (@true@).
metricDataQuery_returnData :: Lens.Lens' MetricDataQuery (Prelude.Maybe Prelude.Bool)
metricDataQuery_returnData :: Lens' MetricDataQuery (Maybe Bool)
metricDataQuery_returnData = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDataQuery' {Maybe Bool
returnData :: Maybe Bool
$sel:returnData:MetricDataQuery' :: MetricDataQuery -> Maybe Bool
returnData} -> Maybe Bool
returnData) (\s :: MetricDataQuery
s@MetricDataQuery' {} Maybe Bool
a -> MetricDataQuery
s {$sel:returnData:MetricDataQuery' :: Maybe Bool
returnData = Maybe Bool
a} :: MetricDataQuery)

-- | A short name that identifies the object\'s results in the response. This
-- name must be unique among all @MetricDataQuery@ objects specified for a
-- single scaling policy. If you are performing math expressions on this
-- set of data, this name represents that data and can serve as a variable
-- in the mathematical expression. The valid characters are letters,
-- numbers, and underscores. The first character must be a lowercase
-- letter.
metricDataQuery_id :: Lens.Lens' MetricDataQuery Prelude.Text
metricDataQuery_id :: Lens' MetricDataQuery Text
metricDataQuery_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDataQuery' {Text
id :: Text
$sel:id:MetricDataQuery' :: MetricDataQuery -> Text
id} -> Text
id) (\s :: MetricDataQuery
s@MetricDataQuery' {} Text
a -> MetricDataQuery
s {$sel:id:MetricDataQuery' :: Text
id = Text
a} :: MetricDataQuery)

instance Data.FromXML MetricDataQuery where
  parseXML :: [Node] -> Either String MetricDataQuery
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> Maybe MetricStat
-> Maybe Bool
-> Text
-> MetricDataQuery
MetricDataQuery'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Expression")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Label")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"MetricStat")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"ReturnData")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Id")

instance Prelude.Hashable MetricDataQuery where
  hashWithSalt :: Int -> MetricDataQuery -> Int
hashWithSalt Int
_salt MetricDataQuery' {Maybe Bool
Maybe Text
Maybe MetricStat
Text
id :: Text
returnData :: Maybe Bool
metricStat :: Maybe MetricStat
label :: Maybe Text
expression :: Maybe Text
$sel:id:MetricDataQuery' :: MetricDataQuery -> Text
$sel:returnData:MetricDataQuery' :: MetricDataQuery -> Maybe Bool
$sel:metricStat:MetricDataQuery' :: MetricDataQuery -> Maybe MetricStat
$sel:label:MetricDataQuery' :: MetricDataQuery -> Maybe Text
$sel:expression:MetricDataQuery' :: MetricDataQuery -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
expression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
label
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe MetricStat
metricStat
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
returnData
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id

instance Prelude.NFData MetricDataQuery where
  rnf :: MetricDataQuery -> ()
rnf MetricDataQuery' {Maybe Bool
Maybe Text
Maybe MetricStat
Text
id :: Text
returnData :: Maybe Bool
metricStat :: Maybe MetricStat
label :: Maybe Text
expression :: Maybe Text
$sel:id:MetricDataQuery' :: MetricDataQuery -> Text
$sel:returnData:MetricDataQuery' :: MetricDataQuery -> Maybe Bool
$sel:metricStat:MetricDataQuery' :: MetricDataQuery -> Maybe MetricStat
$sel:label:MetricDataQuery' :: MetricDataQuery -> Maybe Text
$sel:expression:MetricDataQuery' :: MetricDataQuery -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
expression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
label
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe MetricStat
metricStat
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
returnData
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id

instance Data.ToQuery MetricDataQuery where
  toQuery :: MetricDataQuery -> QueryString
toQuery MetricDataQuery' {Maybe Bool
Maybe Text
Maybe MetricStat
Text
id :: Text
returnData :: Maybe Bool
metricStat :: Maybe MetricStat
label :: Maybe Text
expression :: Maybe Text
$sel:id:MetricDataQuery' :: MetricDataQuery -> Text
$sel:returnData:MetricDataQuery' :: MetricDataQuery -> Maybe Bool
$sel:metricStat:MetricDataQuery' :: MetricDataQuery -> Maybe MetricStat
$sel:label:MetricDataQuery' :: MetricDataQuery -> Maybe Text
$sel:expression:MetricDataQuery' :: MetricDataQuery -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Expression" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
expression,
        ByteString
"Label" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
label,
        ByteString
"MetricStat" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe MetricStat
metricStat,
        ByteString
"ReturnData" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Bool
returnData,
        ByteString
"Id" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
id
      ]