{-# 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.AttributeConfig
-- 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.AttributeConfig 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

-- | Provides information about the method used to transform attributes.
--
-- The following is an example using the RETAIL domain:
--
-- @{@
--
-- @\"AttributeName\": \"demand\",@
--
-- @\"Transformations\": {\"aggregation\": \"sum\", \"middlefill\": \"zero\", \"backfill\": \"zero\"}@
--
-- @}@
--
-- /See:/ 'newAttributeConfig' smart constructor.
data AttributeConfig = AttributeConfig'
  { -- | The name of the attribute as specified in the schema. Amazon Forecast
    -- supports the target field of the target time series and the related time
    -- series datasets. For example, for the RETAIL domain, the target is
    -- @demand@.
    AttributeConfig -> Text
attributeName :: Prelude.Text,
    -- | The method parameters (key-value pairs), which are a map of override
    -- parameters. Specify these parameters to override the default values.
    -- Related Time Series attributes do not accept aggregation parameters.
    --
    -- The following list shows the parameters and their valid values for the
    -- \"filling\" featurization method for a __Target Time Series__ dataset.
    -- Default values are bolded.
    --
    -- -   @aggregation@: __sum__, @avg@, @first@, @min@, @max@
    --
    -- -   @frontfill@: __none__
    --
    -- -   @middlefill@: __zero__, @nan@ (not a number), @value@, @median@,
    --     @mean@, @min@, @max@
    --
    -- -   @backfill@: __zero__, @nan@, @value@, @median@, @mean@, @min@, @max@
    --
    -- The following list shows the parameters and their valid values for a
    -- __Related Time Series__ featurization method (there are no defaults):
    --
    -- -   @middlefill@: @zero@, @value@, @median@, @mean@, @min@, @max@
    --
    -- -   @backfill@: @zero@, @value@, @median@, @mean@, @min@, @max@
    --
    -- -   @futurefill@: @zero@, @value@, @median@, @mean@, @min@, @max@
    --
    -- To set a filling method to a specific value, set the fill parameter to
    -- @value@ and define the value in a corresponding @_value@ parameter. For
    -- example, to set backfilling to a value of 2, include the following:
    -- @\"backfill\": \"value\"@ and @\"backfill_value\":\"2\"@.
    AttributeConfig -> HashMap Text Text
transformations :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (AttributeConfig -> AttributeConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttributeConfig -> AttributeConfig -> Bool
$c/= :: AttributeConfig -> AttributeConfig -> Bool
== :: AttributeConfig -> AttributeConfig -> Bool
$c== :: AttributeConfig -> AttributeConfig -> Bool
Prelude.Eq, ReadPrec [AttributeConfig]
ReadPrec AttributeConfig
Int -> ReadS AttributeConfig
ReadS [AttributeConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttributeConfig]
$creadListPrec :: ReadPrec [AttributeConfig]
readPrec :: ReadPrec AttributeConfig
$creadPrec :: ReadPrec AttributeConfig
readList :: ReadS [AttributeConfig]
$creadList :: ReadS [AttributeConfig]
readsPrec :: Int -> ReadS AttributeConfig
$creadsPrec :: Int -> ReadS AttributeConfig
Prelude.Read, Int -> AttributeConfig -> ShowS
[AttributeConfig] -> ShowS
AttributeConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttributeConfig] -> ShowS
$cshowList :: [AttributeConfig] -> ShowS
show :: AttributeConfig -> String
$cshow :: AttributeConfig -> String
showsPrec :: Int -> AttributeConfig -> ShowS
$cshowsPrec :: Int -> AttributeConfig -> ShowS
Prelude.Show, forall x. Rep AttributeConfig x -> AttributeConfig
forall x. AttributeConfig -> Rep AttributeConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttributeConfig x -> AttributeConfig
$cfrom :: forall x. AttributeConfig -> Rep AttributeConfig x
Prelude.Generic)

-- |
-- Create a value of 'AttributeConfig' 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', 'attributeConfig_attributeName' - The name of the attribute as specified in the schema. Amazon Forecast
-- supports the target field of the target time series and the related time
-- series datasets. For example, for the RETAIL domain, the target is
-- @demand@.
--
-- 'transformations', 'attributeConfig_transformations' - The method parameters (key-value pairs), which are a map of override
-- parameters. Specify these parameters to override the default values.
-- Related Time Series attributes do not accept aggregation parameters.
--
-- The following list shows the parameters and their valid values for the
-- \"filling\" featurization method for a __Target Time Series__ dataset.
-- Default values are bolded.
--
-- -   @aggregation@: __sum__, @avg@, @first@, @min@, @max@
--
-- -   @frontfill@: __none__
--
-- -   @middlefill@: __zero__, @nan@ (not a number), @value@, @median@,
--     @mean@, @min@, @max@
--
-- -   @backfill@: __zero__, @nan@, @value@, @median@, @mean@, @min@, @max@
--
-- The following list shows the parameters and their valid values for a
-- __Related Time Series__ featurization method (there are no defaults):
--
-- -   @middlefill@: @zero@, @value@, @median@, @mean@, @min@, @max@
--
-- -   @backfill@: @zero@, @value@, @median@, @mean@, @min@, @max@
--
-- -   @futurefill@: @zero@, @value@, @median@, @mean@, @min@, @max@
--
-- To set a filling method to a specific value, set the fill parameter to
-- @value@ and define the value in a corresponding @_value@ parameter. For
-- example, to set backfilling to a value of 2, include the following:
-- @\"backfill\": \"value\"@ and @\"backfill_value\":\"2\"@.
newAttributeConfig ::
  -- | 'attributeName'
  Prelude.Text ->
  AttributeConfig
newAttributeConfig :: Text -> AttributeConfig
newAttributeConfig Text
pAttributeName_ =
  AttributeConfig'
    { $sel:attributeName:AttributeConfig' :: Text
attributeName = Text
pAttributeName_,
      $sel:transformations:AttributeConfig' :: HashMap Text Text
transformations = forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the attribute as specified in the schema. Amazon Forecast
-- supports the target field of the target time series and the related time
-- series datasets. For example, for the RETAIL domain, the target is
-- @demand@.
attributeConfig_attributeName :: Lens.Lens' AttributeConfig Prelude.Text
attributeConfig_attributeName :: Lens' AttributeConfig Text
attributeConfig_attributeName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeConfig' {Text
attributeName :: Text
$sel:attributeName:AttributeConfig' :: AttributeConfig -> Text
attributeName} -> Text
attributeName) (\s :: AttributeConfig
s@AttributeConfig' {} Text
a -> AttributeConfig
s {$sel:attributeName:AttributeConfig' :: Text
attributeName = Text
a} :: AttributeConfig)

-- | The method parameters (key-value pairs), which are a map of override
-- parameters. Specify these parameters to override the default values.
-- Related Time Series attributes do not accept aggregation parameters.
--
-- The following list shows the parameters and their valid values for the
-- \"filling\" featurization method for a __Target Time Series__ dataset.
-- Default values are bolded.
--
-- -   @aggregation@: __sum__, @avg@, @first@, @min@, @max@
--
-- -   @frontfill@: __none__
--
-- -   @middlefill@: __zero__, @nan@ (not a number), @value@, @median@,
--     @mean@, @min@, @max@
--
-- -   @backfill@: __zero__, @nan@, @value@, @median@, @mean@, @min@, @max@
--
-- The following list shows the parameters and their valid values for a
-- __Related Time Series__ featurization method (there are no defaults):
--
-- -   @middlefill@: @zero@, @value@, @median@, @mean@, @min@, @max@
--
-- -   @backfill@: @zero@, @value@, @median@, @mean@, @min@, @max@
--
-- -   @futurefill@: @zero@, @value@, @median@, @mean@, @min@, @max@
--
-- To set a filling method to a specific value, set the fill parameter to
-- @value@ and define the value in a corresponding @_value@ parameter. For
-- example, to set backfilling to a value of 2, include the following:
-- @\"backfill\": \"value\"@ and @\"backfill_value\":\"2\"@.
attributeConfig_transformations :: Lens.Lens' AttributeConfig (Prelude.HashMap Prelude.Text Prelude.Text)
attributeConfig_transformations :: Lens' AttributeConfig (HashMap Text Text)
attributeConfig_transformations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeConfig' {HashMap Text Text
transformations :: HashMap Text Text
$sel:transformations:AttributeConfig' :: AttributeConfig -> HashMap Text Text
transformations} -> HashMap Text Text
transformations) (\s :: AttributeConfig
s@AttributeConfig' {} HashMap Text Text
a -> AttributeConfig
s {$sel:transformations:AttributeConfig' :: HashMap Text Text
transformations = HashMap Text Text
a} :: AttributeConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON AttributeConfig where
  parseJSON :: Value -> Parser AttributeConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AttributeConfig"
      ( \Object
x ->
          Text -> HashMap Text Text -> AttributeConfig
AttributeConfig'
            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 (Maybe a)
Data..:? Key
"Transformations"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable AttributeConfig where
  hashWithSalt :: Int -> AttributeConfig -> Int
hashWithSalt Int
_salt AttributeConfig' {Text
HashMap Text Text
transformations :: HashMap Text Text
attributeName :: Text
$sel:transformations:AttributeConfig' :: AttributeConfig -> HashMap Text Text
$sel:attributeName:AttributeConfig' :: AttributeConfig -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
attributeName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text Text
transformations

instance Prelude.NFData AttributeConfig where
  rnf :: AttributeConfig -> ()
rnf AttributeConfig' {Text
HashMap Text Text
transformations :: HashMap Text Text
attributeName :: Text
$sel:transformations:AttributeConfig' :: AttributeConfig -> HashMap Text Text
$sel:attributeName:AttributeConfig' :: AttributeConfig -> 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 HashMap Text Text
transformations

instance Data.ToJSON AttributeConfig where
  toJSON :: AttributeConfig -> Value
toJSON AttributeConfig' {Text
HashMap Text Text
transformations :: HashMap Text Text
attributeName :: Text
$sel:transformations:AttributeConfig' :: AttributeConfig -> HashMap Text Text
$sel:attributeName:AttributeConfig' :: AttributeConfig -> 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
"Transformations" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HashMap Text Text
transformations)
          ]
      )