{-# 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.IoTAnalytics.Types.AddAttributesActivity
-- 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.IoTAnalytics.Types.AddAttributesActivity where

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

-- | An activity that adds other attributes based on existing attributes in
-- the message.
--
-- /See:/ 'newAddAttributesActivity' smart constructor.
data AddAttributesActivity = AddAttributesActivity'
  { -- | The next activity in the pipeline.
    AddAttributesActivity -> Maybe Text
next :: Prelude.Maybe Prelude.Text,
    -- | The name of the addAttributes activity.
    AddAttributesActivity -> Text
name :: Prelude.Text,
    -- | A list of 1-50 @AttributeNameMapping@ objects that map an existing
    -- attribute to a new attribute.
    --
    -- The existing attributes remain in the message, so if you want to remove
    -- the originals, use @RemoveAttributeActivity@.
    AddAttributesActivity -> HashMap Text Text
attributes :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (AddAttributesActivity -> AddAttributesActivity -> Bool
(AddAttributesActivity -> AddAttributesActivity -> Bool)
-> (AddAttributesActivity -> AddAttributesActivity -> Bool)
-> Eq AddAttributesActivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddAttributesActivity -> AddAttributesActivity -> Bool
$c/= :: AddAttributesActivity -> AddAttributesActivity -> Bool
== :: AddAttributesActivity -> AddAttributesActivity -> Bool
$c== :: AddAttributesActivity -> AddAttributesActivity -> Bool
Prelude.Eq, ReadPrec [AddAttributesActivity]
ReadPrec AddAttributesActivity
Int -> ReadS AddAttributesActivity
ReadS [AddAttributesActivity]
(Int -> ReadS AddAttributesActivity)
-> ReadS [AddAttributesActivity]
-> ReadPrec AddAttributesActivity
-> ReadPrec [AddAttributesActivity]
-> Read AddAttributesActivity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddAttributesActivity]
$creadListPrec :: ReadPrec [AddAttributesActivity]
readPrec :: ReadPrec AddAttributesActivity
$creadPrec :: ReadPrec AddAttributesActivity
readList :: ReadS [AddAttributesActivity]
$creadList :: ReadS [AddAttributesActivity]
readsPrec :: Int -> ReadS AddAttributesActivity
$creadsPrec :: Int -> ReadS AddAttributesActivity
Prelude.Read, Int -> AddAttributesActivity -> ShowS
[AddAttributesActivity] -> ShowS
AddAttributesActivity -> String
(Int -> AddAttributesActivity -> ShowS)
-> (AddAttributesActivity -> String)
-> ([AddAttributesActivity] -> ShowS)
-> Show AddAttributesActivity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddAttributesActivity] -> ShowS
$cshowList :: [AddAttributesActivity] -> ShowS
show :: AddAttributesActivity -> String
$cshow :: AddAttributesActivity -> String
showsPrec :: Int -> AddAttributesActivity -> ShowS
$cshowsPrec :: Int -> AddAttributesActivity -> ShowS
Prelude.Show, (forall x. AddAttributesActivity -> Rep AddAttributesActivity x)
-> (forall x. Rep AddAttributesActivity x -> AddAttributesActivity)
-> Generic AddAttributesActivity
forall x. Rep AddAttributesActivity x -> AddAttributesActivity
forall x. AddAttributesActivity -> Rep AddAttributesActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddAttributesActivity x -> AddAttributesActivity
$cfrom :: forall x. AddAttributesActivity -> Rep AddAttributesActivity x
Prelude.Generic)

-- |
-- Create a value of 'AddAttributesActivity' 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:
--
-- 'next', 'addAttributesActivity_next' - The next activity in the pipeline.
--
-- 'name', 'addAttributesActivity_name' - The name of the addAttributes activity.
--
-- 'attributes', 'addAttributesActivity_attributes' - A list of 1-50 @AttributeNameMapping@ objects that map an existing
-- attribute to a new attribute.
--
-- The existing attributes remain in the message, so if you want to remove
-- the originals, use @RemoveAttributeActivity@.
newAddAttributesActivity ::
  -- | 'name'
  Prelude.Text ->
  AddAttributesActivity
newAddAttributesActivity :: Text -> AddAttributesActivity
newAddAttributesActivity Text
pName_ =
  AddAttributesActivity' :: Maybe Text -> Text -> HashMap Text Text -> AddAttributesActivity
AddAttributesActivity'
    { $sel:next:AddAttributesActivity' :: Maybe Text
next = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:AddAttributesActivity' :: Text
name = Text
pName_,
      $sel:attributes:AddAttributesActivity' :: HashMap Text Text
attributes = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty
    }

-- | The next activity in the pipeline.
addAttributesActivity_next :: Lens.Lens' AddAttributesActivity (Prelude.Maybe Prelude.Text)
addAttributesActivity_next :: (Maybe Text -> f (Maybe Text))
-> AddAttributesActivity -> f AddAttributesActivity
addAttributesActivity_next = (AddAttributesActivity -> Maybe Text)
-> (AddAttributesActivity -> Maybe Text -> AddAttributesActivity)
-> Lens
     AddAttributesActivity
     AddAttributesActivity
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddAttributesActivity' {Maybe Text
next :: Maybe Text
$sel:next:AddAttributesActivity' :: AddAttributesActivity -> Maybe Text
next} -> Maybe Text
next) (\s :: AddAttributesActivity
s@AddAttributesActivity' {} Maybe Text
a -> AddAttributesActivity
s {$sel:next:AddAttributesActivity' :: Maybe Text
next = Maybe Text
a} :: AddAttributesActivity)

-- | The name of the addAttributes activity.
addAttributesActivity_name :: Lens.Lens' AddAttributesActivity Prelude.Text
addAttributesActivity_name :: (Text -> f Text)
-> AddAttributesActivity -> f AddAttributesActivity
addAttributesActivity_name = (AddAttributesActivity -> Text)
-> (AddAttributesActivity -> Text -> AddAttributesActivity)
-> Lens AddAttributesActivity AddAttributesActivity Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddAttributesActivity' {Text
name :: Text
$sel:name:AddAttributesActivity' :: AddAttributesActivity -> Text
name} -> Text
name) (\s :: AddAttributesActivity
s@AddAttributesActivity' {} Text
a -> AddAttributesActivity
s {$sel:name:AddAttributesActivity' :: Text
name = Text
a} :: AddAttributesActivity)

-- | A list of 1-50 @AttributeNameMapping@ objects that map an existing
-- attribute to a new attribute.
--
-- The existing attributes remain in the message, so if you want to remove
-- the originals, use @RemoveAttributeActivity@.
addAttributesActivity_attributes :: Lens.Lens' AddAttributesActivity (Prelude.HashMap Prelude.Text Prelude.Text)
addAttributesActivity_attributes :: (HashMap Text Text -> f (HashMap Text Text))
-> AddAttributesActivity -> f AddAttributesActivity
addAttributesActivity_attributes = (AddAttributesActivity -> HashMap Text Text)
-> (AddAttributesActivity
    -> HashMap Text Text -> AddAttributesActivity)
-> Lens
     AddAttributesActivity
     AddAttributesActivity
     (HashMap Text Text)
     (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddAttributesActivity' {HashMap Text Text
attributes :: HashMap Text Text
$sel:attributes:AddAttributesActivity' :: AddAttributesActivity -> HashMap Text Text
attributes} -> HashMap Text Text
attributes) (\s :: AddAttributesActivity
s@AddAttributesActivity' {} HashMap Text Text
a -> AddAttributesActivity
s {$sel:attributes:AddAttributesActivity' :: HashMap Text Text
attributes = HashMap Text Text
a} :: AddAttributesActivity) ((HashMap Text Text -> f (HashMap Text Text))
 -> AddAttributesActivity -> f AddAttributesActivity)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> AddAttributesActivity
-> f AddAttributesActivity
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON AddAttributesActivity where
  parseJSON :: Value -> Parser AddAttributesActivity
parseJSON =
    String
-> (Object -> Parser AddAttributesActivity)
-> Value
-> Parser AddAttributesActivity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AddAttributesActivity"
      ( \Object
x ->
          Maybe Text -> Text -> HashMap Text Text -> AddAttributesActivity
AddAttributesActivity'
            (Maybe Text -> Text -> HashMap Text Text -> AddAttributesActivity)
-> Parser (Maybe Text)
-> Parser (Text -> HashMap Text Text -> AddAttributesActivity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"next")
            Parser (Text -> HashMap Text Text -> AddAttributesActivity)
-> Parser Text
-> Parser (HashMap Text Text -> AddAttributesActivity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name")
            Parser (HashMap Text Text -> AddAttributesActivity)
-> Parser (HashMap Text Text) -> Parser AddAttributesActivity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (HashMap Text Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"attributes" Parser (Maybe (HashMap Text Text))
-> HashMap Text Text -> Parser (HashMap Text Text)
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= HashMap Text Text
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable AddAttributesActivity

instance Prelude.NFData AddAttributesActivity

instance Core.ToJSON AddAttributesActivity where
  toJSON :: AddAttributesActivity -> Value
toJSON AddAttributesActivity' {Maybe Text
Text
HashMap Text Text
attributes :: HashMap Text Text
name :: Text
next :: Maybe Text
$sel:attributes:AddAttributesActivity' :: AddAttributesActivity -> HashMap Text Text
$sel:name:AddAttributesActivity' :: AddAttributesActivity -> Text
$sel:next:AddAttributesActivity' :: AddAttributesActivity -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"next" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
next,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"attributes" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
attributes)
          ]
      )