{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoT.Types.TimestreamAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.TimestreamDimension
import Amazonka.IoT.Types.TimestreamTimestamp
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
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]
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
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. 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'
      { $sel:timestamp:TimestreamAction' :: Maybe TimestreamTimestamp
timestamp = 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 = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced 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 :: Lens' TimestreamAction (Maybe TimestreamTimestamp)
timestreamAction_timestamp = 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 :: Lens' TimestreamAction Text
timestreamAction_roleArn = 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 :: Lens' TimestreamAction Text
timestreamAction_databaseName = 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 :: Lens' TimestreamAction Text
timestreamAction_tableName = 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 :: Lens' TimestreamAction (NonEmpty TimestreamDimension)
timestreamAction_dimensions = 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) 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 TimestreamAction where
  parseJSON :: Value -> Parser TimestreamAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TimestreamAction"
      ( \Object
x ->
          Maybe TimestreamTimestamp
-> Text
-> Text
-> Text
-> NonEmpty TimestreamDimension
-> TimestreamAction
TimestreamAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"timestamp")
            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
"roleArn")
            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
"databaseName")
            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
"tableName")
            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
"dimensions")
      )

instance Prelude.Hashable TimestreamAction where
  hashWithSalt :: Int -> TimestreamAction -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe TimestreamTimestamp
timestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
databaseName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
tableName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty TimestreamDimension
dimensions

instance Prelude.NFData TimestreamAction where
  rnf :: TimestreamAction -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe TimestreamTimestamp
timestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
roleArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
databaseName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
tableName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty TimestreamDimension
dimensions

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"timestamp" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimestreamTimestamp
timestamp,
            forall a. a -> Maybe a
Prelude.Just (Key
"roleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
roleArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"databaseName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
databaseName),
            forall a. a -> Maybe a
Prelude.Just (Key
"tableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
tableName),
            forall a. a -> Maybe a
Prelude.Just (Key
"dimensions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty TimestreamDimension
dimensions)
          ]
      )