{-# 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.Personalize.Types.MetricAttribute
-- 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.Personalize.Types.MetricAttribute 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

-- | Contains information on a metric that a metric attribution reports on.
-- For more information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/measuring-recommendation-impact.html Measuring impact of recommendations>.
--
-- /See:/ 'newMetricAttribute' smart constructor.
data MetricAttribute = MetricAttribute'
  { -- | The metric\'s event type.
    MetricAttribute -> Text
eventType :: Prelude.Text,
    -- | The metric\'s name. The name helps you identify the metric in Amazon
    -- CloudWatch or Amazon S3.
    MetricAttribute -> Text
metricName :: Prelude.Text,
    -- | The attribute\'s expression. Available functions are @SUM()@ or
    -- @SAMPLECOUNT()@. For SUM() functions, provide the dataset type (either
    -- Interactions or Items) and column to sum as a parameter. For example
    -- SUM(Items.PRICE).
    MetricAttribute -> Text
expression :: Prelude.Text
  }
  deriving (MetricAttribute -> MetricAttribute -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricAttribute -> MetricAttribute -> Bool
$c/= :: MetricAttribute -> MetricAttribute -> Bool
== :: MetricAttribute -> MetricAttribute -> Bool
$c== :: MetricAttribute -> MetricAttribute -> Bool
Prelude.Eq, ReadPrec [MetricAttribute]
ReadPrec MetricAttribute
Int -> ReadS MetricAttribute
ReadS [MetricAttribute]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricAttribute]
$creadListPrec :: ReadPrec [MetricAttribute]
readPrec :: ReadPrec MetricAttribute
$creadPrec :: ReadPrec MetricAttribute
readList :: ReadS [MetricAttribute]
$creadList :: ReadS [MetricAttribute]
readsPrec :: Int -> ReadS MetricAttribute
$creadsPrec :: Int -> ReadS MetricAttribute
Prelude.Read, Int -> MetricAttribute -> ShowS
[MetricAttribute] -> ShowS
MetricAttribute -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricAttribute] -> ShowS
$cshowList :: [MetricAttribute] -> ShowS
show :: MetricAttribute -> String
$cshow :: MetricAttribute -> String
showsPrec :: Int -> MetricAttribute -> ShowS
$cshowsPrec :: Int -> MetricAttribute -> ShowS
Prelude.Show, forall x. Rep MetricAttribute x -> MetricAttribute
forall x. MetricAttribute -> Rep MetricAttribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricAttribute x -> MetricAttribute
$cfrom :: forall x. MetricAttribute -> Rep MetricAttribute x
Prelude.Generic)

-- |
-- Create a value of 'MetricAttribute' 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:
--
-- 'eventType', 'metricAttribute_eventType' - The metric\'s event type.
--
-- 'metricName', 'metricAttribute_metricName' - The metric\'s name. The name helps you identify the metric in Amazon
-- CloudWatch or Amazon S3.
--
-- 'expression', 'metricAttribute_expression' - The attribute\'s expression. Available functions are @SUM()@ or
-- @SAMPLECOUNT()@. For SUM() functions, provide the dataset type (either
-- Interactions or Items) and column to sum as a parameter. For example
-- SUM(Items.PRICE).
newMetricAttribute ::
  -- | 'eventType'
  Prelude.Text ->
  -- | 'metricName'
  Prelude.Text ->
  -- | 'expression'
  Prelude.Text ->
  MetricAttribute
newMetricAttribute :: Text -> Text -> Text -> MetricAttribute
newMetricAttribute
  Text
pEventType_
  Text
pMetricName_
  Text
pExpression_ =
    MetricAttribute'
      { $sel:eventType:MetricAttribute' :: Text
eventType = Text
pEventType_,
        $sel:metricName:MetricAttribute' :: Text
metricName = Text
pMetricName_,
        $sel:expression:MetricAttribute' :: Text
expression = Text
pExpression_
      }

-- | The metric\'s event type.
metricAttribute_eventType :: Lens.Lens' MetricAttribute Prelude.Text
metricAttribute_eventType :: Lens' MetricAttribute Text
metricAttribute_eventType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricAttribute' {Text
eventType :: Text
$sel:eventType:MetricAttribute' :: MetricAttribute -> Text
eventType} -> Text
eventType) (\s :: MetricAttribute
s@MetricAttribute' {} Text
a -> MetricAttribute
s {$sel:eventType:MetricAttribute' :: Text
eventType = Text
a} :: MetricAttribute)

-- | The metric\'s name. The name helps you identify the metric in Amazon
-- CloudWatch or Amazon S3.
metricAttribute_metricName :: Lens.Lens' MetricAttribute Prelude.Text
metricAttribute_metricName :: Lens' MetricAttribute Text
metricAttribute_metricName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricAttribute' {Text
metricName :: Text
$sel:metricName:MetricAttribute' :: MetricAttribute -> Text
metricName} -> Text
metricName) (\s :: MetricAttribute
s@MetricAttribute' {} Text
a -> MetricAttribute
s {$sel:metricName:MetricAttribute' :: Text
metricName = Text
a} :: MetricAttribute)

-- | The attribute\'s expression. Available functions are @SUM()@ or
-- @SAMPLECOUNT()@. For SUM() functions, provide the dataset type (either
-- Interactions or Items) and column to sum as a parameter. For example
-- SUM(Items.PRICE).
metricAttribute_expression :: Lens.Lens' MetricAttribute Prelude.Text
metricAttribute_expression :: Lens' MetricAttribute Text
metricAttribute_expression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricAttribute' {Text
expression :: Text
$sel:expression:MetricAttribute' :: MetricAttribute -> Text
expression} -> Text
expression) (\s :: MetricAttribute
s@MetricAttribute' {} Text
a -> MetricAttribute
s {$sel:expression:MetricAttribute' :: Text
expression = Text
a} :: MetricAttribute)

instance Data.FromJSON MetricAttribute where
  parseJSON :: Value -> Parser MetricAttribute
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MetricAttribute"
      ( \Object
x ->
          Text -> Text -> Text -> MetricAttribute
MetricAttribute'
            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
"eventType")
            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
"metricName")
            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
"expression")
      )

instance Prelude.Hashable MetricAttribute where
  hashWithSalt :: Int -> MetricAttribute -> Int
hashWithSalt Int
_salt MetricAttribute' {Text
expression :: Text
metricName :: Text
eventType :: Text
$sel:expression:MetricAttribute' :: MetricAttribute -> Text
$sel:metricName:MetricAttribute' :: MetricAttribute -> Text
$sel:eventType:MetricAttribute' :: MetricAttribute -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
eventType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
metricName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
expression

instance Prelude.NFData MetricAttribute where
  rnf :: MetricAttribute -> ()
rnf MetricAttribute' {Text
expression :: Text
metricName :: Text
eventType :: Text
$sel:expression:MetricAttribute' :: MetricAttribute -> Text
$sel:metricName:MetricAttribute' :: MetricAttribute -> Text
$sel:eventType:MetricAttribute' :: MetricAttribute -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
eventType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
metricName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
expression

instance Data.ToJSON MetricAttribute where
  toJSON :: MetricAttribute -> Value
toJSON MetricAttribute' {Text
expression :: Text
metricName :: Text
eventType :: Text
$sel:expression:MetricAttribute' :: MetricAttribute -> Text
$sel:metricName:MetricAttribute' :: MetricAttribute -> Text
$sel:eventType:MetricAttribute' :: MetricAttribute -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"eventType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
eventType),
            forall a. a -> Maybe a
Prelude.Just (Key
"metricName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
metricName),
            forall a. a -> Maybe a
Prelude.Just (Key
"expression" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
expression)
          ]
      )