{-# 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.DevicePosition
-- 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.DevicePosition where

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

-- | Contains the device position details.
--
-- /See:/ 'newDevicePosition' smart constructor.
data DevicePosition = DevicePosition'
  { -- | The device whose position you retrieved.
    DevicePosition -> Maybe Text
deviceId :: Prelude.Maybe Prelude.Text,
    -- | The last known device position.
    DevicePosition -> Sensitive (NonEmpty Double)
position :: Core.Sensitive (Prelude.NonEmpty Prelude.Double),
    -- | The timestamp for when the tracker resource received the device position
    -- in <https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601>
    -- format: @YYYY-MM-DDThh:mm:ss.sssZ@.
    DevicePosition -> POSIX
receivedTime :: Core.POSIX,
    -- | 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@.
    DevicePosition -> POSIX
sampleTime :: Core.POSIX
  }
  deriving (DevicePosition -> DevicePosition -> Bool
(DevicePosition -> DevicePosition -> Bool)
-> (DevicePosition -> DevicePosition -> Bool) -> Eq DevicePosition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DevicePosition -> DevicePosition -> Bool
$c/= :: DevicePosition -> DevicePosition -> Bool
== :: DevicePosition -> DevicePosition -> Bool
$c== :: DevicePosition -> DevicePosition -> Bool
Prelude.Eq, Int -> DevicePosition -> ShowS
[DevicePosition] -> ShowS
DevicePosition -> String
(Int -> DevicePosition -> ShowS)
-> (DevicePosition -> String)
-> ([DevicePosition] -> ShowS)
-> Show DevicePosition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DevicePosition] -> ShowS
$cshowList :: [DevicePosition] -> ShowS
show :: DevicePosition -> String
$cshow :: DevicePosition -> String
showsPrec :: Int -> DevicePosition -> ShowS
$cshowsPrec :: Int -> DevicePosition -> ShowS
Prelude.Show, (forall x. DevicePosition -> Rep DevicePosition x)
-> (forall x. Rep DevicePosition x -> DevicePosition)
-> Generic DevicePosition
forall x. Rep DevicePosition x -> DevicePosition
forall x. DevicePosition -> Rep DevicePosition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DevicePosition x -> DevicePosition
$cfrom :: forall x. DevicePosition -> Rep DevicePosition x
Prelude.Generic)

-- |
-- Create a value of 'DevicePosition' 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', 'devicePosition_deviceId' - The device whose position you retrieved.
--
-- 'position', 'devicePosition_position' - The last known device position.
--
-- 'receivedTime', 'devicePosition_receivedTime' - The timestamp for when the tracker resource received the device position
-- in <https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601>
-- format: @YYYY-MM-DDThh:mm:ss.sssZ@.
--
-- 'sampleTime', 'devicePosition_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@.
newDevicePosition ::
  -- | 'position'
  Prelude.NonEmpty Prelude.Double ->
  -- | 'receivedTime'
  Prelude.UTCTime ->
  -- | 'sampleTime'
  Prelude.UTCTime ->
  DevicePosition
newDevicePosition :: NonEmpty Double -> UTCTime -> UTCTime -> DevicePosition
newDevicePosition
  NonEmpty Double
pPosition_
  UTCTime
pReceivedTime_
  UTCTime
pSampleTime_ =
    DevicePosition' :: Maybe Text
-> Sensitive (NonEmpty Double) -> POSIX -> POSIX -> DevicePosition
DevicePosition'
      { $sel:deviceId:DevicePosition' :: Maybe Text
deviceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:position:DevicePosition' :: 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:receivedTime:DevicePosition' :: POSIX
receivedTime = 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
pReceivedTime_,
        $sel:sampleTime:DevicePosition' :: 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 whose position you retrieved.
devicePosition_deviceId :: Lens.Lens' DevicePosition (Prelude.Maybe Prelude.Text)
devicePosition_deviceId :: (Maybe Text -> f (Maybe Text))
-> DevicePosition -> f DevicePosition
devicePosition_deviceId = (DevicePosition -> Maybe Text)
-> (DevicePosition -> Maybe Text -> DevicePosition)
-> Lens DevicePosition DevicePosition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePosition' {Maybe Text
deviceId :: Maybe Text
$sel:deviceId:DevicePosition' :: DevicePosition -> Maybe Text
deviceId} -> Maybe Text
deviceId) (\s :: DevicePosition
s@DevicePosition' {} Maybe Text
a -> DevicePosition
s {$sel:deviceId:DevicePosition' :: Maybe Text
deviceId = Maybe Text
a} :: DevicePosition)

-- | The last known device position.
devicePosition_position :: Lens.Lens' DevicePosition (Prelude.NonEmpty Prelude.Double)
devicePosition_position :: (NonEmpty Double -> f (NonEmpty Double))
-> DevicePosition -> f DevicePosition
devicePosition_position = (DevicePosition -> Sensitive (NonEmpty Double))
-> (DevicePosition
    -> Sensitive (NonEmpty Double) -> DevicePosition)
-> Lens
     DevicePosition
     DevicePosition
     (Sensitive (NonEmpty Double))
     (Sensitive (NonEmpty Double))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePosition' {Sensitive (NonEmpty Double)
position :: Sensitive (NonEmpty Double)
$sel:position:DevicePosition' :: DevicePosition -> Sensitive (NonEmpty Double)
position} -> Sensitive (NonEmpty Double)
position) (\s :: DevicePosition
s@DevicePosition' {} Sensitive (NonEmpty Double)
a -> DevicePosition
s {$sel:position:DevicePosition' :: Sensitive (NonEmpty Double)
position = Sensitive (NonEmpty Double)
a} :: DevicePosition) ((Sensitive (NonEmpty Double) -> f (Sensitive (NonEmpty Double)))
 -> DevicePosition -> f DevicePosition)
-> ((NonEmpty Double -> f (NonEmpty Double))
    -> Sensitive (NonEmpty Double) -> f (Sensitive (NonEmpty Double)))
-> (NonEmpty Double -> f (NonEmpty Double))
-> DevicePosition
-> f DevicePosition
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 for when the tracker resource received the device position
-- in <https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601>
-- format: @YYYY-MM-DDThh:mm:ss.sssZ@.
devicePosition_receivedTime :: Lens.Lens' DevicePosition Prelude.UTCTime
devicePosition_receivedTime :: (UTCTime -> f UTCTime) -> DevicePosition -> f DevicePosition
devicePosition_receivedTime = (DevicePosition -> POSIX)
-> (DevicePosition -> POSIX -> DevicePosition)
-> Lens DevicePosition DevicePosition POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePosition' {POSIX
receivedTime :: POSIX
$sel:receivedTime:DevicePosition' :: DevicePosition -> POSIX
receivedTime} -> POSIX
receivedTime) (\s :: DevicePosition
s@DevicePosition' {} POSIX
a -> DevicePosition
s {$sel:receivedTime:DevicePosition' :: POSIX
receivedTime = POSIX
a} :: DevicePosition) ((POSIX -> f POSIX) -> DevicePosition -> f DevicePosition)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> DevicePosition
-> f DevicePosition
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

-- | 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@.
devicePosition_sampleTime :: Lens.Lens' DevicePosition Prelude.UTCTime
devicePosition_sampleTime :: (UTCTime -> f UTCTime) -> DevicePosition -> f DevicePosition
devicePosition_sampleTime = (DevicePosition -> POSIX)
-> (DevicePosition -> POSIX -> DevicePosition)
-> Lens DevicePosition DevicePosition POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DevicePosition' {POSIX
sampleTime :: POSIX
$sel:sampleTime:DevicePosition' :: DevicePosition -> POSIX
sampleTime} -> POSIX
sampleTime) (\s :: DevicePosition
s@DevicePosition' {} POSIX
a -> DevicePosition
s {$sel:sampleTime:DevicePosition' :: POSIX
sampleTime = POSIX
a} :: DevicePosition) ((POSIX -> f POSIX) -> DevicePosition -> f DevicePosition)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> DevicePosition
-> f DevicePosition
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 Core.FromJSON DevicePosition where
  parseJSON :: Value -> Parser DevicePosition
parseJSON =
    String
-> (Object -> Parser DevicePosition)
-> Value
-> Parser DevicePosition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DevicePosition"
      ( \Object
x ->
          Maybe Text
-> Sensitive (NonEmpty Double) -> POSIX -> POSIX -> DevicePosition
DevicePosition'
            (Maybe Text
 -> Sensitive (NonEmpty Double) -> POSIX -> POSIX -> DevicePosition)
-> Parser (Maybe Text)
-> Parser
     (Sensitive (NonEmpty Double) -> POSIX -> POSIX -> DevicePosition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DeviceId")
            Parser
  (Sensitive (NonEmpty Double) -> POSIX -> POSIX -> DevicePosition)
-> Parser (Sensitive (NonEmpty Double))
-> Parser (POSIX -> POSIX -> DevicePosition)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Sensitive (NonEmpty Double))
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Position")
            Parser (POSIX -> POSIX -> DevicePosition)
-> Parser POSIX -> Parser (POSIX -> DevicePosition)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ReceivedTime")
            Parser (POSIX -> DevicePosition)
-> Parser POSIX -> Parser DevicePosition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"SampleTime")
      )

instance Prelude.Hashable DevicePosition

instance Prelude.NFData DevicePosition