{-# 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.Forecast.Types.Action
-- 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.Forecast.Types.Action where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Forecast.Types.Operation
import qualified Amazonka.Prelude as Prelude

-- | Defines the modifications that you are making to an attribute for a
-- what-if forecast. For example, you can use this operation to create a
-- what-if forecast that investigates a 10% off sale on all shoes. To do
-- this, you specify @\"AttributeName\": \"shoes\"@,
-- @\"Operation\": \"MULTIPLY\"@, and @\"Value\": \"0.90\"@. Pair this
-- operation with the TimeSeriesCondition operation within the
-- CreateWhatIfForecastRequest$TimeSeriesTransformations operation to
-- define a subset of attribute items that are modified.
--
-- /See:/ 'newAction' smart constructor.
data Action = Action'
  { -- | The related time series that you are modifying. This value is case
    -- insensitive.
    Action -> Text
attributeName :: Prelude.Text,
    -- | The operation that is applied to the provided attribute. Operations
    -- include:
    --
    -- -   @ADD@ - adds @Value@ to all rows of @AttributeName@.
    --
    -- -   @SUBTRACT@ - subtracts @Value@ from all rows of @AttributeName@.
    --
    -- -   @MULTIPLY@ - multiplies all rows of @AttributeName@ by @Value@.
    --
    -- -   @DIVIDE@ - divides all rows of @AttributeName@ by @Value@.
    Action -> Operation
operation :: Operation,
    -- | The value that is applied for the chosen @Operation@.
    Action -> Double
value :: Prelude.Double
  }
  deriving (Action -> Action -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Action -> Action -> Bool
$c/= :: Action -> Action -> Bool
== :: Action -> Action -> Bool
$c== :: Action -> Action -> Bool
Prelude.Eq, ReadPrec [Action]
ReadPrec Action
Int -> ReadS Action
ReadS [Action]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Action]
$creadListPrec :: ReadPrec [Action]
readPrec :: ReadPrec Action
$creadPrec :: ReadPrec Action
readList :: ReadS [Action]
$creadList :: ReadS [Action]
readsPrec :: Int -> ReadS Action
$creadsPrec :: Int -> ReadS Action
Prelude.Read, Int -> Action -> ShowS
[Action] -> ShowS
Action -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Action] -> ShowS
$cshowList :: [Action] -> ShowS
show :: Action -> String
$cshow :: Action -> String
showsPrec :: Int -> Action -> ShowS
$cshowsPrec :: Int -> Action -> ShowS
Prelude.Show, forall x. Rep Action x -> Action
forall x. Action -> Rep Action x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Action x -> Action
$cfrom :: forall x. Action -> Rep Action x
Prelude.Generic)

-- |
-- Create a value of 'Action' 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:
--
-- 'attributeName', 'action_attributeName' - The related time series that you are modifying. This value is case
-- insensitive.
--
-- 'operation', 'action_operation' - The operation that is applied to the provided attribute. Operations
-- include:
--
-- -   @ADD@ - adds @Value@ to all rows of @AttributeName@.
--
-- -   @SUBTRACT@ - subtracts @Value@ from all rows of @AttributeName@.
--
-- -   @MULTIPLY@ - multiplies all rows of @AttributeName@ by @Value@.
--
-- -   @DIVIDE@ - divides all rows of @AttributeName@ by @Value@.
--
-- 'value', 'action_value' - The value that is applied for the chosen @Operation@.
newAction ::
  -- | 'attributeName'
  Prelude.Text ->
  -- | 'operation'
  Operation ->
  -- | 'value'
  Prelude.Double ->
  Action
newAction :: Text -> Operation -> Double -> Action
newAction Text
pAttributeName_ Operation
pOperation_ Double
pValue_ =
  Action'
    { $sel:attributeName:Action' :: Text
attributeName = Text
pAttributeName_,
      $sel:operation:Action' :: Operation
operation = Operation
pOperation_,
      $sel:value:Action' :: Double
value = Double
pValue_
    }

-- | The related time series that you are modifying. This value is case
-- insensitive.
action_attributeName :: Lens.Lens' Action Prelude.Text
action_attributeName :: Lens' Action Text
action_attributeName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Text
attributeName :: Text
$sel:attributeName:Action' :: Action -> Text
attributeName} -> Text
attributeName) (\s :: Action
s@Action' {} Text
a -> Action
s {$sel:attributeName:Action' :: Text
attributeName = Text
a} :: Action)

-- | The operation that is applied to the provided attribute. Operations
-- include:
--
-- -   @ADD@ - adds @Value@ to all rows of @AttributeName@.
--
-- -   @SUBTRACT@ - subtracts @Value@ from all rows of @AttributeName@.
--
-- -   @MULTIPLY@ - multiplies all rows of @AttributeName@ by @Value@.
--
-- -   @DIVIDE@ - divides all rows of @AttributeName@ by @Value@.
action_operation :: Lens.Lens' Action Operation
action_operation :: Lens' Action Operation
action_operation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Operation
operation :: Operation
$sel:operation:Action' :: Action -> Operation
operation} -> Operation
operation) (\s :: Action
s@Action' {} Operation
a -> Action
s {$sel:operation:Action' :: Operation
operation = Operation
a} :: Action)

-- | The value that is applied for the chosen @Operation@.
action_value :: Lens.Lens' Action Prelude.Double
action_value :: Lens' Action Double
action_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Double
value :: Double
$sel:value:Action' :: Action -> Double
value} -> Double
value) (\s :: Action
s@Action' {} Double
a -> Action
s {$sel:value:Action' :: Double
value = Double
a} :: Action)

instance Data.FromJSON Action where
  parseJSON :: Value -> Parser Action
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Action"
      ( \Object
x ->
          Text -> Operation -> Double -> Action
Action'
            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
"AttributeName")
            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
"Operation")
            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
"Value")
      )

instance Prelude.Hashable Action where
  hashWithSalt :: Int -> Action -> Int
hashWithSalt Int
_salt Action' {Double
Text
Operation
value :: Double
operation :: Operation
attributeName :: Text
$sel:value:Action' :: Action -> Double
$sel:operation:Action' :: Action -> Operation
$sel:attributeName:Action' :: Action -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
attributeName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Operation
operation
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
value

instance Prelude.NFData Action where
  rnf :: Action -> ()
rnf Action' {Double
Text
Operation
value :: Double
operation :: Operation
attributeName :: Text
$sel:value:Action' :: Action -> Double
$sel:operation:Action' :: Action -> Operation
$sel:attributeName:Action' :: Action -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
attributeName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Operation
operation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Double
value

instance Data.ToJSON Action where
  toJSON :: Action -> Value
toJSON Action' {Double
Text
Operation
value :: Double
operation :: Operation
attributeName :: Text
$sel:value:Action' :: Action -> Double
$sel:operation:Action' :: Action -> Operation
$sel:attributeName:Action' :: Action -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"AttributeName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
attributeName),
            forall a. a -> Maybe a
Prelude.Just (Key
"Operation" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Operation
operation),
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Double
value)
          ]
      )