{-# 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.IoT.Types.TimestreamAction
-- 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.IoT.Types.TimestreamAction where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.TimestreamDimension
import Amazonka.IoT.Types.TimestreamTimestamp
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The Timestream rule action writes attributes (measures) from an MQTT
-- message into an Amazon Timestream table. For more information, see the
-- <https://docs.aws.amazon.com/iot/latest/developerguide/timestream-rule-action.html Timestream>
-- topic rule action documentation.
--
-- /See:/ 'newTimestreamAction' smart constructor.
data TimestreamAction = TimestreamAction'
  { -- | Specifies an application-defined value to replace the default value
    -- assigned to the Timestream record\'s timestamp in the @time@ column.
    --
    -- You can use this property to specify the value and the precision of the
    -- Timestream record\'s timestamp. You can specify a value from the message
    -- payload or a value computed by a substitution template.
    --
    -- If omitted, the topic rule action assigns the timestamp, in
    -- milliseconds, at the time it processed the rule.
    TimestreamAction -> Maybe TimestreamTimestamp
timestamp :: Prelude.Maybe TimestreamTimestamp,
    -- | The ARN of the role that grants permission to write to the Amazon
    -- Timestream database table.
    TimestreamAction -> Text
roleArn :: Prelude.Text,
    -- | The name of an Amazon Timestream database.
    TimestreamAction -> Text
databaseName :: Prelude.Text,
    -- | The name of the database table into which to write the measure records.
    TimestreamAction -> Text
tableName :: Prelude.Text,
    -- | Metadata attributes of the time series that are written in each measure
    -- record.
    TimestreamAction -> NonEmpty TimestreamDimension
dimensions :: Prelude.NonEmpty TimestreamDimension
  }
  deriving (TimestreamAction -> TimestreamAction -> Bool
(TimestreamAction -> TimestreamAction -> Bool)
-> (TimestreamAction -> TimestreamAction -> Bool)
-> Eq TimestreamAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimestreamAction -> TimestreamAction -> Bool
$c/= :: TimestreamAction -> TimestreamAction -> Bool
== :: TimestreamAction -> TimestreamAction -> Bool
$c== :: TimestreamAction -> TimestreamAction -> Bool
Prelude.Eq, ReadPrec [TimestreamAction]
ReadPrec TimestreamAction
Int -> ReadS TimestreamAction
ReadS [TimestreamAction]
(Int -> ReadS TimestreamAction)
-> ReadS [TimestreamAction]
-> ReadPrec TimestreamAction
-> ReadPrec [TimestreamAction]
-> Read TimestreamAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimestreamAction]
$creadListPrec :: ReadPrec [TimestreamAction]
readPrec :: ReadPrec TimestreamAction
$creadPrec :: ReadPrec TimestreamAction
readList :: ReadS [TimestreamAction]
$creadList :: ReadS [TimestreamAction]
readsPrec :: Int -> ReadS TimestreamAction
$creadsPrec :: Int -> ReadS TimestreamAction
Prelude.Read, Int -> TimestreamAction -> ShowS
[TimestreamAction] -> ShowS
TimestreamAction -> String
(Int -> TimestreamAction -> ShowS)
-> (TimestreamAction -> String)
-> ([TimestreamAction] -> ShowS)
-> Show TimestreamAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimestreamAction] -> ShowS
$cshowList :: [TimestreamAction] -> ShowS
show :: TimestreamAction -> String
$cshow :: TimestreamAction -> String
showsPrec :: Int -> TimestreamAction -> ShowS
$cshowsPrec :: Int -> TimestreamAction -> ShowS
Prelude.Show, (forall x. TimestreamAction -> Rep TimestreamAction x)
-> (forall x. Rep TimestreamAction x -> TimestreamAction)
-> Generic TimestreamAction
forall x. Rep TimestreamAction x -> TimestreamAction
forall x. TimestreamAction -> Rep TimestreamAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimestreamAction x -> TimestreamAction
$cfrom :: forall x. TimestreamAction -> Rep TimestreamAction x
Prelude.Generic)

-- |
-- Create a value of 'TimestreamAction' 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:
--
-- 'timestamp', 'timestreamAction_timestamp' - Specifies an application-defined value to replace the default value
-- assigned to the Timestream record\'s timestamp in the @time@ column.
--
-- You can use this property to specify the value and the precision of the
-- Timestream record\'s timestamp. You can specify a value from the message
-- payload or a value computed by a substitution template.
--
-- If omitted, the topic rule action assigns the timestamp, in
-- milliseconds, at the time it processed the rule.
--
-- 'roleArn', 'timestreamAction_roleArn' - The ARN of the role that grants permission to write to the Amazon
-- Timestream database table.
--
-- 'databaseName', 'timestreamAction_databaseName' - The name of an Amazon Timestream database.
--
-- 'tableName', 'timestreamAction_tableName' - The name of the database table into which to write the measure records.
--
-- 'dimensions', 'timestreamAction_dimensions' - Metadata attributes of the time series that are written in each measure
-- record.
newTimestreamAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'tableName'
  Prelude.Text ->
  -- | 'dimensions'
  Prelude.NonEmpty TimestreamDimension ->
  TimestreamAction
newTimestreamAction :: Text
-> Text -> Text -> NonEmpty TimestreamDimension -> TimestreamAction
newTimestreamAction
  Text
pRoleArn_
  Text
pDatabaseName_
  Text
pTableName_
  NonEmpty TimestreamDimension
pDimensions_ =
    TimestreamAction' :: Maybe TimestreamTimestamp
-> Text
-> Text
-> Text
-> NonEmpty TimestreamDimension
-> TimestreamAction
TimestreamAction'
      { $sel:timestamp:TimestreamAction' :: Maybe TimestreamTimestamp
timestamp = Maybe TimestreamTimestamp
forall a. Maybe a
Prelude.Nothing,
        $sel:roleArn:TimestreamAction' :: Text
roleArn = Text
pRoleArn_,
        $sel:databaseName:TimestreamAction' :: Text
databaseName = Text
pDatabaseName_,
        $sel:tableName:TimestreamAction' :: Text
tableName = Text
pTableName_,
        $sel:dimensions:TimestreamAction' :: NonEmpty TimestreamDimension
dimensions = Tagged
  (NonEmpty TimestreamDimension)
  (Identity (NonEmpty TimestreamDimension))
-> Tagged
     (NonEmpty TimestreamDimension)
     (Identity (NonEmpty TimestreamDimension))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty TimestreamDimension)
   (Identity (NonEmpty TimestreamDimension))
 -> Tagged
      (NonEmpty TimestreamDimension)
      (Identity (NonEmpty TimestreamDimension)))
-> NonEmpty TimestreamDimension -> NonEmpty TimestreamDimension
forall t b. AReview t b -> b -> t
Lens.# NonEmpty TimestreamDimension
pDimensions_
      }

-- | Specifies an application-defined value to replace the default value
-- assigned to the Timestream record\'s timestamp in the @time@ column.
--
-- You can use this property to specify the value and the precision of the
-- Timestream record\'s timestamp. You can specify a value from the message
-- payload or a value computed by a substitution template.
--
-- If omitted, the topic rule action assigns the timestamp, in
-- milliseconds, at the time it processed the rule.
timestreamAction_timestamp :: Lens.Lens' TimestreamAction (Prelude.Maybe TimestreamTimestamp)
timestreamAction_timestamp :: (Maybe TimestreamTimestamp -> f (Maybe TimestreamTimestamp))
-> TimestreamAction -> f TimestreamAction
timestreamAction_timestamp = (TimestreamAction -> Maybe TimestreamTimestamp)
-> (TimestreamAction
    -> Maybe TimestreamTimestamp -> TimestreamAction)
-> Lens
     TimestreamAction
     TimestreamAction
     (Maybe TimestreamTimestamp)
     (Maybe TimestreamTimestamp)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimestreamAction' {Maybe TimestreamTimestamp
timestamp :: Maybe TimestreamTimestamp
$sel:timestamp:TimestreamAction' :: TimestreamAction -> Maybe TimestreamTimestamp
timestamp} -> Maybe TimestreamTimestamp
timestamp) (\s :: TimestreamAction
s@TimestreamAction' {} Maybe TimestreamTimestamp
a -> TimestreamAction
s {$sel:timestamp:TimestreamAction' :: Maybe TimestreamTimestamp
timestamp = Maybe TimestreamTimestamp
a} :: TimestreamAction)

-- | The ARN of the role that grants permission to write to the Amazon
-- Timestream database table.
timestreamAction_roleArn :: Lens.Lens' TimestreamAction Prelude.Text
timestreamAction_roleArn :: (Text -> f Text) -> TimestreamAction -> f TimestreamAction
timestreamAction_roleArn = (TimestreamAction -> Text)
-> (TimestreamAction -> Text -> TimestreamAction)
-> Lens TimestreamAction TimestreamAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimestreamAction' {Text
roleArn :: Text
$sel:roleArn:TimestreamAction' :: TimestreamAction -> Text
roleArn} -> Text
roleArn) (\s :: TimestreamAction
s@TimestreamAction' {} Text
a -> TimestreamAction
s {$sel:roleArn:TimestreamAction' :: Text
roleArn = Text
a} :: TimestreamAction)

-- | The name of an Amazon Timestream database.
timestreamAction_databaseName :: Lens.Lens' TimestreamAction Prelude.Text
timestreamAction_databaseName :: (Text -> f Text) -> TimestreamAction -> f TimestreamAction
timestreamAction_databaseName = (TimestreamAction -> Text)
-> (TimestreamAction -> Text -> TimestreamAction)
-> Lens TimestreamAction TimestreamAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimestreamAction' {Text
databaseName :: Text
$sel:databaseName:TimestreamAction' :: TimestreamAction -> Text
databaseName} -> Text
databaseName) (\s :: TimestreamAction
s@TimestreamAction' {} Text
a -> TimestreamAction
s {$sel:databaseName:TimestreamAction' :: Text
databaseName = Text
a} :: TimestreamAction)

-- | The name of the database table into which to write the measure records.
timestreamAction_tableName :: Lens.Lens' TimestreamAction Prelude.Text
timestreamAction_tableName :: (Text -> f Text) -> TimestreamAction -> f TimestreamAction
timestreamAction_tableName = (TimestreamAction -> Text)
-> (TimestreamAction -> Text -> TimestreamAction)
-> Lens TimestreamAction TimestreamAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimestreamAction' {Text
tableName :: Text
$sel:tableName:TimestreamAction' :: TimestreamAction -> Text
tableName} -> Text
tableName) (\s :: TimestreamAction
s@TimestreamAction' {} Text
a -> TimestreamAction
s {$sel:tableName:TimestreamAction' :: Text
tableName = Text
a} :: TimestreamAction)

-- | Metadata attributes of the time series that are written in each measure
-- record.
timestreamAction_dimensions :: Lens.Lens' TimestreamAction (Prelude.NonEmpty TimestreamDimension)
timestreamAction_dimensions :: (NonEmpty TimestreamDimension -> f (NonEmpty TimestreamDimension))
-> TimestreamAction -> f TimestreamAction
timestreamAction_dimensions = (TimestreamAction -> NonEmpty TimestreamDimension)
-> (TimestreamAction
    -> NonEmpty TimestreamDimension -> TimestreamAction)
-> Lens
     TimestreamAction
     TimestreamAction
     (NonEmpty TimestreamDimension)
     (NonEmpty TimestreamDimension)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimestreamAction' {NonEmpty TimestreamDimension
dimensions :: NonEmpty TimestreamDimension
$sel:dimensions:TimestreamAction' :: TimestreamAction -> NonEmpty TimestreamDimension
dimensions} -> NonEmpty TimestreamDimension
dimensions) (\s :: TimestreamAction
s@TimestreamAction' {} NonEmpty TimestreamDimension
a -> TimestreamAction
s {$sel:dimensions:TimestreamAction' :: NonEmpty TimestreamDimension
dimensions = NonEmpty TimestreamDimension
a} :: TimestreamAction) ((NonEmpty TimestreamDimension -> f (NonEmpty TimestreamDimension))
 -> TimestreamAction -> f TimestreamAction)
-> ((NonEmpty TimestreamDimension
     -> f (NonEmpty TimestreamDimension))
    -> NonEmpty TimestreamDimension
    -> f (NonEmpty TimestreamDimension))
-> (NonEmpty TimestreamDimension
    -> f (NonEmpty TimestreamDimension))
-> TimestreamAction
-> f TimestreamAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty TimestreamDimension -> f (NonEmpty TimestreamDimension))
-> NonEmpty TimestreamDimension -> f (NonEmpty TimestreamDimension)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON TimestreamAction where
  parseJSON :: Value -> Parser TimestreamAction
parseJSON =
    String
-> (Object -> Parser TimestreamAction)
-> Value
-> Parser TimestreamAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TimestreamAction"
      ( \Object
x ->
          Maybe TimestreamTimestamp
-> Text
-> Text
-> Text
-> NonEmpty TimestreamDimension
-> TimestreamAction
TimestreamAction'
            (Maybe TimestreamTimestamp
 -> Text
 -> Text
 -> Text
 -> NonEmpty TimestreamDimension
 -> TimestreamAction)
-> Parser (Maybe TimestreamTimestamp)
-> Parser
     (Text
      -> Text
      -> Text
      -> NonEmpty TimestreamDimension
      -> TimestreamAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe TimestreamTimestamp)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"timestamp")
            Parser
  (Text
   -> Text
   -> Text
   -> NonEmpty TimestreamDimension
   -> TimestreamAction)
-> Parser Text
-> Parser
     (Text -> Text -> NonEmpty TimestreamDimension -> TimestreamAction)
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
"roleArn")
            Parser
  (Text -> Text -> NonEmpty TimestreamDimension -> TimestreamAction)
-> Parser Text
-> Parser
     (Text -> NonEmpty TimestreamDimension -> TimestreamAction)
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
"databaseName")
            Parser (Text -> NonEmpty TimestreamDimension -> TimestreamAction)
-> Parser Text
-> Parser (NonEmpty TimestreamDimension -> TimestreamAction)
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
"tableName")
            Parser (NonEmpty TimestreamDimension -> TimestreamAction)
-> Parser (NonEmpty TimestreamDimension) -> Parser TimestreamAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty TimestreamDimension)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"dimensions")
      )

instance Prelude.Hashable TimestreamAction

instance Prelude.NFData TimestreamAction

instance Core.ToJSON TimestreamAction where
  toJSON :: TimestreamAction -> Value
toJSON TimestreamAction' {Maybe TimestreamTimestamp
NonEmpty TimestreamDimension
Text
dimensions :: NonEmpty TimestreamDimension
tableName :: Text
databaseName :: Text
roleArn :: Text
timestamp :: Maybe TimestreamTimestamp
$sel:dimensions:TimestreamAction' :: TimestreamAction -> NonEmpty TimestreamDimension
$sel:tableName:TimestreamAction' :: TimestreamAction -> Text
$sel:databaseName:TimestreamAction' :: TimestreamAction -> Text
$sel:roleArn:TimestreamAction' :: TimestreamAction -> Text
$sel:timestamp:TimestreamAction' :: TimestreamAction -> Maybe TimestreamTimestamp
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"timestamp" Text -> TimestreamTimestamp -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (TimestreamTimestamp -> Pair)
-> Maybe TimestreamTimestamp -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimestreamTimestamp
timestamp,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"databaseName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
databaseName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"tableName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
tableName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"dimensions" Text -> NonEmpty TimestreamDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty TimestreamDimension
dimensions)
          ]
      )