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

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

-- | Contains the position update details for a device.
--
-- /See:/ 'newDevicePositionUpdate' smart constructor.
data DevicePositionUpdate = DevicePositionUpdate'
  { -- | The device associated to the position update.
    DevicePositionUpdate -> Text
deviceId :: Prelude.Text,
    -- | The latest device position defined in
    -- <https://earth-info.nga.mil/GandG/wgs84/index.html WGS 84> format:
    -- @[X or longitude, Y or latitude]@.
    DevicePositionUpdate -> Sensitive (NonEmpty Double)
position :: Core.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 -> POSIX
sampleTime :: Core.POSIX
  }
  deriving (DevicePositionUpdate -> DevicePositionUpdate -> Bool
(DevicePositionUpdate -> DevicePositionUpdate -> Bool)
-> (DevicePositionUpdate -> DevicePositionUpdate -> Bool)
-> Eq DevicePositionUpdate
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
(Int -> DevicePositionUpdate -> ShowS)
-> (DevicePositionUpdate -> String)
-> ([DevicePositionUpdate] -> ShowS)
-> Show DevicePositionUpdate
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. DevicePositionUpdate -> Rep DevicePositionUpdate x)
-> (forall x. Rep DevicePositionUpdate x -> DevicePositionUpdate)
-> Generic DevicePositionUpdate
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:
--
-- 'deviceId', 'devicePositionUpdate_deviceId' - The device associated to the position update.
--
-- 'position', 'devicePositionUpdate_position' - The latest device position defined in
-- <https://earth-info.nga.mil/GandG/wgs84/index.html 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' :: Text
-> Sensitive (NonEmpty Double) -> POSIX -> DevicePositionUpdate
DevicePositionUpdate'
      { $sel:deviceId:DevicePositionUpdate' :: Text
deviceId = Text
pDeviceId_,
        $sel:position:DevicePositionUpdate' :: Sensitive (NonEmpty Double)
position =
          Tagged (NonEmpty Double) (Identity (NonEmpty Double))
-> Tagged
     (Sensitive (NonEmpty Double))
     (Identity (Sensitive (NonEmpty Double)))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged (NonEmpty Double) (Identity (NonEmpty Double))
 -> Tagged
      (Sensitive (NonEmpty Double))
      (Identity (Sensitive (NonEmpty Double))))
-> (Tagged (NonEmpty Double) (Identity (NonEmpty Double))
    -> Tagged (NonEmpty Double) (Identity (NonEmpty Double)))
-> Tagged (NonEmpty Double) (Identity (NonEmpty Double))
-> Tagged
     (Sensitive (NonEmpty Double))
     (Identity (Sensitive (NonEmpty Double)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Tagged (NonEmpty Double) (Identity (NonEmpty Double))
-> Tagged (NonEmpty Double) (Identity (NonEmpty Double))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced
            (Tagged (NonEmpty Double) (Identity (NonEmpty Double))
 -> Tagged
      (Sensitive (NonEmpty Double))
      (Identity (Sensitive (NonEmpty Double))))
-> NonEmpty Double -> Sensitive (NonEmpty Double)
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Double
pPosition_,
        $sel:sampleTime:DevicePositionUpdate' :: POSIX
sampleTime = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pSampleTime_
      }

-- | The device associated to the position update.
devicePositionUpdate_deviceId :: Lens.Lens' DevicePositionUpdate Prelude.Text
devicePositionUpdate_deviceId :: (Text -> f Text) -> DevicePositionUpdate -> f DevicePositionUpdate
devicePositionUpdate_deviceId = (DevicePositionUpdate -> Text)
-> (DevicePositionUpdate -> Text -> DevicePositionUpdate)
-> Lens DevicePositionUpdate DevicePositionUpdate Text Text
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/GandG/wgs84/index.html WGS 84> format:
-- @[X or longitude, Y or latitude]@.
devicePositionUpdate_position :: Lens.Lens' DevicePositionUpdate (Prelude.NonEmpty Prelude.Double)
devicePositionUpdate_position :: (NonEmpty Double -> f (NonEmpty Double))
-> DevicePositionUpdate -> f DevicePositionUpdate
devicePositionUpdate_position = (DevicePositionUpdate -> Sensitive (NonEmpty Double))
-> (DevicePositionUpdate
    -> Sensitive (NonEmpty Double) -> DevicePositionUpdate)
-> Lens
     DevicePositionUpdate
     DevicePositionUpdate
     (Sensitive (NonEmpty Double))
     (Sensitive (NonEmpty Double))
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) ((Sensitive (NonEmpty Double) -> f (Sensitive (NonEmpty Double)))
 -> DevicePositionUpdate -> f DevicePositionUpdate)
-> ((NonEmpty Double -> f (NonEmpty Double))
    -> Sensitive (NonEmpty Double) -> f (Sensitive (NonEmpty Double)))
-> (NonEmpty Double -> f (NonEmpty Double))
-> DevicePositionUpdate
-> f DevicePositionUpdate
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Double -> f (NonEmpty Double))
-> Sensitive (NonEmpty Double) -> f (Sensitive (NonEmpty Double))
forall a. Iso' (Sensitive a) a
Core._Sensitive ((NonEmpty Double -> f (NonEmpty Double))
 -> Sensitive (NonEmpty Double) -> f (Sensitive (NonEmpty Double)))
-> ((NonEmpty Double -> f (NonEmpty Double))
    -> NonEmpty Double -> f (NonEmpty Double))
-> (NonEmpty Double -> f (NonEmpty Double))
-> Sensitive (NonEmpty Double)
-> f (Sensitive (NonEmpty Double))
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Double -> f (NonEmpty Double))
-> NonEmpty Double -> f (NonEmpty Double)
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 :: (UTCTime -> f UTCTime)
-> DevicePositionUpdate -> f DevicePositionUpdate
devicePositionUpdate_sampleTime = (DevicePositionUpdate -> POSIX)
-> (DevicePositionUpdate -> POSIX -> DevicePositionUpdate)
-> Lens DevicePositionUpdate DevicePositionUpdate POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePositionUpdate' {POSIX
sampleTime :: POSIX
$sel:sampleTime:DevicePositionUpdate' :: DevicePositionUpdate -> POSIX
sampleTime} -> POSIX
sampleTime) (\s :: DevicePositionUpdate
s@DevicePositionUpdate' {} POSIX
a -> DevicePositionUpdate
s {$sel:sampleTime:DevicePositionUpdate' :: POSIX
sampleTime = POSIX
a} :: DevicePositionUpdate) ((POSIX -> f POSIX)
 -> DevicePositionUpdate -> f DevicePositionUpdate)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> DevicePositionUpdate
-> f DevicePositionUpdate
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Prelude.Hashable DevicePositionUpdate

instance Prelude.NFData DevicePositionUpdate

instance Core.ToJSON DevicePositionUpdate where
  toJSON :: DevicePositionUpdate -> Value
toJSON DevicePositionUpdate' {Text
Sensitive (NonEmpty Double)
POSIX
sampleTime :: POSIX
position :: Sensitive (NonEmpty Double)
deviceId :: Text
$sel:sampleTime:DevicePositionUpdate' :: DevicePositionUpdate -> POSIX
$sel:position:DevicePositionUpdate' :: DevicePositionUpdate -> Sensitive (NonEmpty Double)
$sel:deviceId:DevicePositionUpdate' :: DevicePositionUpdate -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DeviceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
deviceId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Position" Text -> Sensitive (NonEmpty Double) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive (NonEmpty Double)
position),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"SampleTime" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= POSIX
sampleTime)
          ]
      )