{-# 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.Location.Types.DevicePositionUpdate
-- 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.Location.Types.DevicePositionUpdate where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Location.Types.PositionalAccuracy
import qualified Amazonka.Prelude as Prelude

-- | Contains the position update details for a device.
--
-- /See:/ 'newDevicePositionUpdate' smart constructor.
data DevicePositionUpdate = DevicePositionUpdate'
  { -- | The accuracy of the device position.
    DevicePositionUpdate -> Maybe PositionalAccuracy
accuracy :: Prelude.Maybe PositionalAccuracy,
    -- | Associates one of more properties with the position update. A property
    -- is a key-value pair stored with the position update and added to any
    -- geofence event the update may trigger.
    --
    -- Format: @\"key\" : \"value\"@
    DevicePositionUpdate -> Maybe (Sensitive (HashMap Text Text))
positionProperties :: Prelude.Maybe (Data.Sensitive (Prelude.HashMap Prelude.Text Prelude.Text)),
    -- | The device associated to the position update.
    DevicePositionUpdate -> Text
deviceId :: Prelude.Text,
    -- | The latest device position defined in
    -- <https://earth-info.nga.mil/index.php?dir=wgs84&action=wgs84 WGS 84>
    -- format: @[X or longitude, Y or latitude]@.
    DevicePositionUpdate -> Sensitive (NonEmpty Double)
position :: Data.Sensitive (Prelude.NonEmpty Prelude.Double),
    -- | The timestamp at which the device\'s position was determined. Uses
    -- <https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601>
    -- format: @YYYY-MM-DDThh:mm:ss.sssZ@
    DevicePositionUpdate -> ISO8601
sampleTime :: Data.ISO8601
  }
  deriving (DevicePositionUpdate -> DevicePositionUpdate -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DevicePositionUpdate -> DevicePositionUpdate -> Bool
$c/= :: DevicePositionUpdate -> DevicePositionUpdate -> Bool
== :: DevicePositionUpdate -> DevicePositionUpdate -> Bool
$c== :: DevicePositionUpdate -> DevicePositionUpdate -> Bool
Prelude.Eq, Int -> DevicePositionUpdate -> ShowS
[DevicePositionUpdate] -> ShowS
DevicePositionUpdate -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DevicePositionUpdate] -> ShowS
$cshowList :: [DevicePositionUpdate] -> ShowS
show :: DevicePositionUpdate -> String
$cshow :: DevicePositionUpdate -> String
showsPrec :: Int -> DevicePositionUpdate -> ShowS
$cshowsPrec :: Int -> DevicePositionUpdate -> ShowS
Prelude.Show, forall x. Rep DevicePositionUpdate x -> DevicePositionUpdate
forall x. DevicePositionUpdate -> Rep DevicePositionUpdate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DevicePositionUpdate x -> DevicePositionUpdate
$cfrom :: forall x. DevicePositionUpdate -> Rep DevicePositionUpdate x
Prelude.Generic)

-- |
-- Create a value of 'DevicePositionUpdate' 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:
--
-- 'accuracy', 'devicePositionUpdate_accuracy' - The accuracy of the device position.
--
-- 'positionProperties', 'devicePositionUpdate_positionProperties' - Associates one of more properties with the position update. A property
-- is a key-value pair stored with the position update and added to any
-- geofence event the update may trigger.
--
-- Format: @\"key\" : \"value\"@
--
-- 'deviceId', 'devicePositionUpdate_deviceId' - The device associated to the position update.
--
-- 'position', 'devicePositionUpdate_position' - The latest device position defined in
-- <https://earth-info.nga.mil/index.php?dir=wgs84&action=wgs84 WGS 84>
-- format: @[X or longitude, Y or latitude]@.
--
-- 'sampleTime', 'devicePositionUpdate_sampleTime' - The timestamp at which the device\'s position was determined. Uses
-- <https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601>
-- format: @YYYY-MM-DDThh:mm:ss.sssZ@
newDevicePositionUpdate ::
  -- | 'deviceId'
  Prelude.Text ->
  -- | 'position'
  Prelude.NonEmpty Prelude.Double ->
  -- | 'sampleTime'
  Prelude.UTCTime ->
  DevicePositionUpdate
newDevicePositionUpdate :: Text -> NonEmpty Double -> UTCTime -> DevicePositionUpdate
newDevicePositionUpdate
  Text
pDeviceId_
  NonEmpty Double
pPosition_
  UTCTime
pSampleTime_ =
    DevicePositionUpdate'
      { $sel:accuracy:DevicePositionUpdate' :: Maybe PositionalAccuracy
accuracy = forall a. Maybe a
Prelude.Nothing,
        $sel:positionProperties:DevicePositionUpdate' :: Maybe (Sensitive (HashMap Text Text))
positionProperties = forall a. Maybe a
Prelude.Nothing,
        $sel:deviceId:DevicePositionUpdate' :: Text
deviceId = Text
pDeviceId_,
        $sel:position:DevicePositionUpdate' :: Sensitive (NonEmpty Double)
position =
          forall a. Iso' (Sensitive a) a
Data._Sensitive
            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
            forall t b. AReview t b -> b -> t
Lens.# NonEmpty Double
pPosition_,
        $sel:sampleTime:DevicePositionUpdate' :: ISO8601
sampleTime = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pSampleTime_
      }

-- | The accuracy of the device position.
devicePositionUpdate_accuracy :: Lens.Lens' DevicePositionUpdate (Prelude.Maybe PositionalAccuracy)
devicePositionUpdate_accuracy :: Lens' DevicePositionUpdate (Maybe PositionalAccuracy)
devicePositionUpdate_accuracy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePositionUpdate' {Maybe PositionalAccuracy
accuracy :: Maybe PositionalAccuracy
$sel:accuracy:DevicePositionUpdate' :: DevicePositionUpdate -> Maybe PositionalAccuracy
accuracy} -> Maybe PositionalAccuracy
accuracy) (\s :: DevicePositionUpdate
s@DevicePositionUpdate' {} Maybe PositionalAccuracy
a -> DevicePositionUpdate
s {$sel:accuracy:DevicePositionUpdate' :: Maybe PositionalAccuracy
accuracy = Maybe PositionalAccuracy
a} :: DevicePositionUpdate)

-- | Associates one of more properties with the position update. A property
-- is a key-value pair stored with the position update and added to any
-- geofence event the update may trigger.
--
-- Format: @\"key\" : \"value\"@
devicePositionUpdate_positionProperties :: Lens.Lens' DevicePositionUpdate (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
devicePositionUpdate_positionProperties :: Lens' DevicePositionUpdate (Maybe (HashMap Text Text))
devicePositionUpdate_positionProperties = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePositionUpdate' {Maybe (Sensitive (HashMap Text Text))
positionProperties :: Maybe (Sensitive (HashMap Text Text))
$sel:positionProperties:DevicePositionUpdate' :: DevicePositionUpdate -> Maybe (Sensitive (HashMap Text Text))
positionProperties} -> Maybe (Sensitive (HashMap Text Text))
positionProperties) (\s :: DevicePositionUpdate
s@DevicePositionUpdate' {} Maybe (Sensitive (HashMap Text Text))
a -> DevicePositionUpdate
s {$sel:positionProperties:DevicePositionUpdate' :: Maybe (Sensitive (HashMap Text Text))
positionProperties = Maybe (Sensitive (HashMap Text Text))
a} :: DevicePositionUpdate) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping (forall a. Iso' (Sensitive a) a
Data._Sensitive 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)

-- | The device associated to the position update.
devicePositionUpdate_deviceId :: Lens.Lens' DevicePositionUpdate Prelude.Text
devicePositionUpdate_deviceId :: Lens' DevicePositionUpdate Text
devicePositionUpdate_deviceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePositionUpdate' {Text
deviceId :: Text
$sel:deviceId:DevicePositionUpdate' :: DevicePositionUpdate -> Text
deviceId} -> Text
deviceId) (\s :: DevicePositionUpdate
s@DevicePositionUpdate' {} Text
a -> DevicePositionUpdate
s {$sel:deviceId:DevicePositionUpdate' :: Text
deviceId = Text
a} :: DevicePositionUpdate)

-- | The latest device position defined in
-- <https://earth-info.nga.mil/index.php?dir=wgs84&action=wgs84 WGS 84>
-- format: @[X or longitude, Y or latitude]@.
devicePositionUpdate_position :: Lens.Lens' DevicePositionUpdate (Prelude.NonEmpty Prelude.Double)
devicePositionUpdate_position :: Lens' DevicePositionUpdate (NonEmpty Double)
devicePositionUpdate_position = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePositionUpdate' {Sensitive (NonEmpty Double)
position :: Sensitive (NonEmpty Double)
$sel:position:DevicePositionUpdate' :: DevicePositionUpdate -> Sensitive (NonEmpty Double)
position} -> Sensitive (NonEmpty Double)
position) (\s :: DevicePositionUpdate
s@DevicePositionUpdate' {} Sensitive (NonEmpty Double)
a -> DevicePositionUpdate
s {$sel:position:DevicePositionUpdate' :: Sensitive (NonEmpty Double)
position = Sensitive (NonEmpty Double)
a} :: DevicePositionUpdate) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive 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

-- | The timestamp at which the device\'s position was determined. Uses
-- <https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601>
-- format: @YYYY-MM-DDThh:mm:ss.sssZ@
devicePositionUpdate_sampleTime :: Lens.Lens' DevicePositionUpdate Prelude.UTCTime
devicePositionUpdate_sampleTime :: Lens' DevicePositionUpdate UTCTime
devicePositionUpdate_sampleTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePositionUpdate' {ISO8601
sampleTime :: ISO8601
$sel:sampleTime:DevicePositionUpdate' :: DevicePositionUpdate -> ISO8601
sampleTime} -> ISO8601
sampleTime) (\s :: DevicePositionUpdate
s@DevicePositionUpdate' {} ISO8601
a -> DevicePositionUpdate
s {$sel:sampleTime:DevicePositionUpdate' :: ISO8601
sampleTime = ISO8601
a} :: DevicePositionUpdate) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

instance Prelude.Hashable DevicePositionUpdate where
  hashWithSalt :: Int -> DevicePositionUpdate -> Int
hashWithSalt Int
_salt DevicePositionUpdate' {Maybe (Sensitive (HashMap Text Text))
Maybe PositionalAccuracy
Text
Sensitive (NonEmpty Double)
ISO8601
sampleTime :: ISO8601
position :: Sensitive (NonEmpty Double)
deviceId :: Text
positionProperties :: Maybe (Sensitive (HashMap Text Text))
accuracy :: Maybe PositionalAccuracy
$sel:sampleTime:DevicePositionUpdate' :: DevicePositionUpdate -> ISO8601
$sel:position:DevicePositionUpdate' :: DevicePositionUpdate -> Sensitive (NonEmpty Double)
$sel:deviceId:DevicePositionUpdate' :: DevicePositionUpdate -> Text
$sel:positionProperties:DevicePositionUpdate' :: DevicePositionUpdate -> Maybe (Sensitive (HashMap Text Text))
$sel:accuracy:DevicePositionUpdate' :: DevicePositionUpdate -> Maybe PositionalAccuracy
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PositionalAccuracy
accuracy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive (HashMap Text Text))
positionProperties
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
deviceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive (NonEmpty Double)
position
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ISO8601
sampleTime

instance Prelude.NFData DevicePositionUpdate where
  rnf :: DevicePositionUpdate -> ()
rnf DevicePositionUpdate' {Maybe (Sensitive (HashMap Text Text))
Maybe PositionalAccuracy
Text
Sensitive (NonEmpty Double)
ISO8601
sampleTime :: ISO8601
position :: Sensitive (NonEmpty Double)
deviceId :: Text
positionProperties :: Maybe (Sensitive (HashMap Text Text))
accuracy :: Maybe PositionalAccuracy
$sel:sampleTime:DevicePositionUpdate' :: DevicePositionUpdate -> ISO8601
$sel:position:DevicePositionUpdate' :: DevicePositionUpdate -> Sensitive (NonEmpty Double)
$sel:deviceId:DevicePositionUpdate' :: DevicePositionUpdate -> Text
$sel:positionProperties:DevicePositionUpdate' :: DevicePositionUpdate -> Maybe (Sensitive (HashMap Text Text))
$sel:accuracy:DevicePositionUpdate' :: DevicePositionUpdate -> Maybe PositionalAccuracy
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe PositionalAccuracy
accuracy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive (HashMap Text Text))
positionProperties
      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 Sensitive (NonEmpty Double)
position
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ISO8601
sampleTime

instance Data.ToJSON DevicePositionUpdate where
  toJSON :: DevicePositionUpdate -> Value
toJSON DevicePositionUpdate' {Maybe (Sensitive (HashMap Text Text))
Maybe PositionalAccuracy
Text
Sensitive (NonEmpty Double)
ISO8601
sampleTime :: ISO8601
position :: Sensitive (NonEmpty Double)
deviceId :: Text
positionProperties :: Maybe (Sensitive (HashMap Text Text))
accuracy :: Maybe PositionalAccuracy
$sel:sampleTime:DevicePositionUpdate' :: DevicePositionUpdate -> ISO8601
$sel:position:DevicePositionUpdate' :: DevicePositionUpdate -> Sensitive (NonEmpty Double)
$sel:deviceId:DevicePositionUpdate' :: DevicePositionUpdate -> Text
$sel:positionProperties:DevicePositionUpdate' :: DevicePositionUpdate -> Maybe (Sensitive (HashMap Text Text))
$sel:accuracy:DevicePositionUpdate' :: DevicePositionUpdate -> Maybe PositionalAccuracy
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Accuracy" 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 PositionalAccuracy
accuracy,
            (Key
"PositionProperties" 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 (Sensitive (HashMap Text Text))
positionProperties,
            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
"Position" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive (NonEmpty Double)
position),
            forall a. a -> Maybe a
Prelude.Just (Key
"SampleTime" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ISO8601
sampleTime)
          ]
      )