{-# 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.LocationAction
-- 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.LocationAction 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.LocationTimestamp
import qualified Amazonka.Prelude as Prelude

-- | The Amazon Location rule action sends device location updates from an
-- MQTT message to an Amazon Location tracker resource.
--
-- /See:/ 'newLocationAction' smart constructor.
data LocationAction = LocationAction'
  { -- | The time that the location data was sampled. The default value is the
    -- time the MQTT message was processed.
    LocationAction -> Maybe LocationTimestamp
timestamp :: Prelude.Maybe LocationTimestamp,
    -- | The IAM role that grants permission to write to the Amazon Location
    -- resource.
    LocationAction -> Text
roleArn :: Prelude.Text,
    -- | The name of the tracker resource in Amazon Location in which the
    -- location is updated.
    LocationAction -> Text
trackerName :: Prelude.Text,
    -- | The unique ID of the device providing the location data.
    LocationAction -> Text
deviceId :: Prelude.Text,
    -- | A string that evaluates to a double value that represents the latitude
    -- of the device\'s location.
    LocationAction -> Text
latitude :: Prelude.Text,
    -- | A string that evaluates to a double value that represents the longitude
    -- of the device\'s location.
    LocationAction -> Text
longitude :: Prelude.Text
  }
  deriving (LocationAction -> LocationAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LocationAction -> LocationAction -> Bool
$c/= :: LocationAction -> LocationAction -> Bool
== :: LocationAction -> LocationAction -> Bool
$c== :: LocationAction -> LocationAction -> Bool
Prelude.Eq, ReadPrec [LocationAction]
ReadPrec LocationAction
Int -> ReadS LocationAction
ReadS [LocationAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LocationAction]
$creadListPrec :: ReadPrec [LocationAction]
readPrec :: ReadPrec LocationAction
$creadPrec :: ReadPrec LocationAction
readList :: ReadS [LocationAction]
$creadList :: ReadS [LocationAction]
readsPrec :: Int -> ReadS LocationAction
$creadsPrec :: Int -> ReadS LocationAction
Prelude.Read, Int -> LocationAction -> ShowS
[LocationAction] -> ShowS
LocationAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LocationAction] -> ShowS
$cshowList :: [LocationAction] -> ShowS
show :: LocationAction -> String
$cshow :: LocationAction -> String
showsPrec :: Int -> LocationAction -> ShowS
$cshowsPrec :: Int -> LocationAction -> ShowS
Prelude.Show, forall x. Rep LocationAction x -> LocationAction
forall x. LocationAction -> Rep LocationAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LocationAction x -> LocationAction
$cfrom :: forall x. LocationAction -> Rep LocationAction x
Prelude.Generic)

-- |
-- Create a value of 'LocationAction' 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', 'locationAction_timestamp' - The time that the location data was sampled. The default value is the
-- time the MQTT message was processed.
--
-- 'roleArn', 'locationAction_roleArn' - The IAM role that grants permission to write to the Amazon Location
-- resource.
--
-- 'trackerName', 'locationAction_trackerName' - The name of the tracker resource in Amazon Location in which the
-- location is updated.
--
-- 'deviceId', 'locationAction_deviceId' - The unique ID of the device providing the location data.
--
-- 'latitude', 'locationAction_latitude' - A string that evaluates to a double value that represents the latitude
-- of the device\'s location.
--
-- 'longitude', 'locationAction_longitude' - A string that evaluates to a double value that represents the longitude
-- of the device\'s location.
newLocationAction ::
  -- | 'roleArn'
  Prelude.Text ->
  -- | 'trackerName'
  Prelude.Text ->
  -- | 'deviceId'
  Prelude.Text ->
  -- | 'latitude'
  Prelude.Text ->
  -- | 'longitude'
  Prelude.Text ->
  LocationAction
newLocationAction :: Text -> Text -> Text -> Text -> Text -> LocationAction
newLocationAction
  Text
pRoleArn_
  Text
pTrackerName_
  Text
pDeviceId_
  Text
pLatitude_
  Text
pLongitude_ =
    LocationAction'
      { $sel:timestamp:LocationAction' :: Maybe LocationTimestamp
timestamp = forall a. Maybe a
Prelude.Nothing,
        $sel:roleArn:LocationAction' :: Text
roleArn = Text
pRoleArn_,
        $sel:trackerName:LocationAction' :: Text
trackerName = Text
pTrackerName_,
        $sel:deviceId:LocationAction' :: Text
deviceId = Text
pDeviceId_,
        $sel:latitude:LocationAction' :: Text
latitude = Text
pLatitude_,
        $sel:longitude:LocationAction' :: Text
longitude = Text
pLongitude_
      }

-- | The time that the location data was sampled. The default value is the
-- time the MQTT message was processed.
locationAction_timestamp :: Lens.Lens' LocationAction (Prelude.Maybe LocationTimestamp)
locationAction_timestamp :: Lens' LocationAction (Maybe LocationTimestamp)
locationAction_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocationAction' {Maybe LocationTimestamp
timestamp :: Maybe LocationTimestamp
$sel:timestamp:LocationAction' :: LocationAction -> Maybe LocationTimestamp
timestamp} -> Maybe LocationTimestamp
timestamp) (\s :: LocationAction
s@LocationAction' {} Maybe LocationTimestamp
a -> LocationAction
s {$sel:timestamp:LocationAction' :: Maybe LocationTimestamp
timestamp = Maybe LocationTimestamp
a} :: LocationAction)

-- | The IAM role that grants permission to write to the Amazon Location
-- resource.
locationAction_roleArn :: Lens.Lens' LocationAction Prelude.Text
locationAction_roleArn :: Lens' LocationAction Text
locationAction_roleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocationAction' {Text
roleArn :: Text
$sel:roleArn:LocationAction' :: LocationAction -> Text
roleArn} -> Text
roleArn) (\s :: LocationAction
s@LocationAction' {} Text
a -> LocationAction
s {$sel:roleArn:LocationAction' :: Text
roleArn = Text
a} :: LocationAction)

-- | The name of the tracker resource in Amazon Location in which the
-- location is updated.
locationAction_trackerName :: Lens.Lens' LocationAction Prelude.Text
locationAction_trackerName :: Lens' LocationAction Text
locationAction_trackerName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocationAction' {Text
trackerName :: Text
$sel:trackerName:LocationAction' :: LocationAction -> Text
trackerName} -> Text
trackerName) (\s :: LocationAction
s@LocationAction' {} Text
a -> LocationAction
s {$sel:trackerName:LocationAction' :: Text
trackerName = Text
a} :: LocationAction)

-- | The unique ID of the device providing the location data.
locationAction_deviceId :: Lens.Lens' LocationAction Prelude.Text
locationAction_deviceId :: Lens' LocationAction Text
locationAction_deviceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocationAction' {Text
deviceId :: Text
$sel:deviceId:LocationAction' :: LocationAction -> Text
deviceId} -> Text
deviceId) (\s :: LocationAction
s@LocationAction' {} Text
a -> LocationAction
s {$sel:deviceId:LocationAction' :: Text
deviceId = Text
a} :: LocationAction)

-- | A string that evaluates to a double value that represents the latitude
-- of the device\'s location.
locationAction_latitude :: Lens.Lens' LocationAction Prelude.Text
locationAction_latitude :: Lens' LocationAction Text
locationAction_latitude = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocationAction' {Text
latitude :: Text
$sel:latitude:LocationAction' :: LocationAction -> Text
latitude} -> Text
latitude) (\s :: LocationAction
s@LocationAction' {} Text
a -> LocationAction
s {$sel:latitude:LocationAction' :: Text
latitude = Text
a} :: LocationAction)

-- | A string that evaluates to a double value that represents the longitude
-- of the device\'s location.
locationAction_longitude :: Lens.Lens' LocationAction Prelude.Text
locationAction_longitude :: Lens' LocationAction Text
locationAction_longitude = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LocationAction' {Text
longitude :: Text
$sel:longitude:LocationAction' :: LocationAction -> Text
longitude} -> Text
longitude) (\s :: LocationAction
s@LocationAction' {} Text
a -> LocationAction
s {$sel:longitude:LocationAction' :: Text
longitude = Text
a} :: LocationAction)

instance Data.FromJSON LocationAction where
  parseJSON :: Value -> Parser LocationAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"LocationAction"
      ( \Object
x ->
          Maybe LocationTimestamp
-> Text -> Text -> Text -> Text -> Text -> LocationAction
LocationAction'
            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
"trackerName")
            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
"deviceId")
            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
"latitude")
            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
"longitude")
      )

instance Prelude.Hashable LocationAction where
  hashWithSalt :: Int -> LocationAction -> Int
hashWithSalt Int
_salt LocationAction' {Maybe LocationTimestamp
Text
longitude :: Text
latitude :: Text
deviceId :: Text
trackerName :: Text
roleArn :: Text
timestamp :: Maybe LocationTimestamp
$sel:longitude:LocationAction' :: LocationAction -> Text
$sel:latitude:LocationAction' :: LocationAction -> Text
$sel:deviceId:LocationAction' :: LocationAction -> Text
$sel:trackerName:LocationAction' :: LocationAction -> Text
$sel:roleArn:LocationAction' :: LocationAction -> Text
$sel:timestamp:LocationAction' :: LocationAction -> Maybe LocationTimestamp
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe LocationTimestamp
timestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
trackerName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
deviceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
latitude
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
longitude

instance Prelude.NFData LocationAction where
  rnf :: LocationAction -> ()
rnf LocationAction' {Maybe LocationTimestamp
Text
longitude :: Text
latitude :: Text
deviceId :: Text
trackerName :: Text
roleArn :: Text
timestamp :: Maybe LocationTimestamp
$sel:longitude:LocationAction' :: LocationAction -> Text
$sel:latitude:LocationAction' :: LocationAction -> Text
$sel:deviceId:LocationAction' :: LocationAction -> Text
$sel:trackerName:LocationAction' :: LocationAction -> Text
$sel:roleArn:LocationAction' :: LocationAction -> Text
$sel:timestamp:LocationAction' :: LocationAction -> Maybe LocationTimestamp
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe LocationTimestamp
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
trackerName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
deviceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
latitude
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
longitude

instance Data.ToJSON LocationAction where
  toJSON :: LocationAction -> Value
toJSON LocationAction' {Maybe LocationTimestamp
Text
longitude :: Text
latitude :: Text
deviceId :: Text
trackerName :: Text
roleArn :: Text
timestamp :: Maybe LocationTimestamp
$sel:longitude:LocationAction' :: LocationAction -> Text
$sel:latitude:LocationAction' :: LocationAction -> Text
$sel:deviceId:LocationAction' :: LocationAction -> Text
$sel:trackerName:LocationAction' :: LocationAction -> Text
$sel:roleArn:LocationAction' :: LocationAction -> Text
$sel:timestamp:LocationAction' :: LocationAction -> Maybe LocationTimestamp
..} =
    [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 LocationTimestamp
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
"trackerName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
trackerName),
            forall a. a -> Maybe a
Prelude.Just (Key
"deviceId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
deviceId),
            forall a. a -> Maybe a
Prelude.Just (Key
"latitude" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
latitude),
            forall a. a -> Maybe a
Prelude.Just (Key
"longitude" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
longitude)
          ]
      )