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

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

-- | Represents an element of a leg within a route. A step contains
-- instructions for how to move to the next step in the leg.
--
-- /See:/ 'newStep' smart constructor.
data Step = Step'
  { -- | Represents the start position, or index, in a sequence of steps within
    -- the leg\'s line string geometry. For example, the index of the first
    -- step in a leg geometry is @0@.
    --
    -- Included in the response for queries that set @IncludeLegGeometry@ to
    -- @True@.
    Step -> Maybe Natural
geometryOffset :: Prelude.Maybe Prelude.Natural,
    -- | The travel distance between the step\'s @StartPosition@ and
    -- @EndPosition@.
    Step -> Double
distance :: Prelude.Double,
    -- | The estimated travel time, in seconds, from the step\'s @StartPosition@
    -- to the @EndPosition@. . The travel mode and departure time that you
    -- specify in the request determines the calculated time.
    Step -> Double
durationSeconds :: Prelude.Double,
    -- | The end position of a step. If the position the last step in the leg,
    -- this position is the same as the end position of the leg.
    Step -> Sensitive (NonEmpty Double)
endPosition :: Data.Sensitive (Prelude.NonEmpty Prelude.Double),
    -- | The starting position of a step. If the position is the first step in
    -- the leg, this position is the same as the start position of the leg.
    Step -> Sensitive (NonEmpty Double)
startPosition :: Data.Sensitive (Prelude.NonEmpty Prelude.Double)
  }
  deriving (Step -> Step -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Step -> Step -> Bool
$c/= :: Step -> Step -> Bool
== :: Step -> Step -> Bool
$c== :: Step -> Step -> Bool
Prelude.Eq, Int -> Step -> ShowS
[Step] -> ShowS
Step -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Step] -> ShowS
$cshowList :: [Step] -> ShowS
show :: Step -> String
$cshow :: Step -> String
showsPrec :: Int -> Step -> ShowS
$cshowsPrec :: Int -> Step -> ShowS
Prelude.Show, forall x. Rep Step x -> Step
forall x. Step -> Rep Step x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Step x -> Step
$cfrom :: forall x. Step -> Rep Step x
Prelude.Generic)

-- |
-- Create a value of 'Step' 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:
--
-- 'geometryOffset', 'step_geometryOffset' - Represents the start position, or index, in a sequence of steps within
-- the leg\'s line string geometry. For example, the index of the first
-- step in a leg geometry is @0@.
--
-- Included in the response for queries that set @IncludeLegGeometry@ to
-- @True@.
--
-- 'distance', 'step_distance' - The travel distance between the step\'s @StartPosition@ and
-- @EndPosition@.
--
-- 'durationSeconds', 'step_durationSeconds' - The estimated travel time, in seconds, from the step\'s @StartPosition@
-- to the @EndPosition@. . The travel mode and departure time that you
-- specify in the request determines the calculated time.
--
-- 'endPosition', 'step_endPosition' - The end position of a step. If the position the last step in the leg,
-- this position is the same as the end position of the leg.
--
-- 'startPosition', 'step_startPosition' - The starting position of a step. If the position is the first step in
-- the leg, this position is the same as the start position of the leg.
newStep ::
  -- | 'distance'
  Prelude.Double ->
  -- | 'durationSeconds'
  Prelude.Double ->
  -- | 'endPosition'
  Prelude.NonEmpty Prelude.Double ->
  -- | 'startPosition'
  Prelude.NonEmpty Prelude.Double ->
  Step
newStep :: Double -> Double -> NonEmpty Double -> NonEmpty Double -> Step
newStep
  Double
pDistance_
  Double
pDurationSeconds_
  NonEmpty Double
pEndPosition_
  NonEmpty Double
pStartPosition_ =
    Step'
      { $sel:geometryOffset:Step' :: Maybe Natural
geometryOffset = forall a. Maybe a
Prelude.Nothing,
        $sel:distance:Step' :: Double
distance = Double
pDistance_,
        $sel:durationSeconds:Step' :: Double
durationSeconds = Double
pDurationSeconds_,
        $sel:endPosition:Step' :: Sensitive (NonEmpty Double)
endPosition =
          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
pEndPosition_,
        $sel:startPosition:Step' :: Sensitive (NonEmpty Double)
startPosition =
          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
pStartPosition_
      }

-- | Represents the start position, or index, in a sequence of steps within
-- the leg\'s line string geometry. For example, the index of the first
-- step in a leg geometry is @0@.
--
-- Included in the response for queries that set @IncludeLegGeometry@ to
-- @True@.
step_geometryOffset :: Lens.Lens' Step (Prelude.Maybe Prelude.Natural)
step_geometryOffset :: Lens' Step (Maybe Natural)
step_geometryOffset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Maybe Natural
geometryOffset :: Maybe Natural
$sel:geometryOffset:Step' :: Step -> Maybe Natural
geometryOffset} -> Maybe Natural
geometryOffset) (\s :: Step
s@Step' {} Maybe Natural
a -> Step
s {$sel:geometryOffset:Step' :: Maybe Natural
geometryOffset = Maybe Natural
a} :: Step)

-- | The travel distance between the step\'s @StartPosition@ and
-- @EndPosition@.
step_distance :: Lens.Lens' Step Prelude.Double
step_distance :: Lens' Step Double
step_distance = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Double
distance :: Double
$sel:distance:Step' :: Step -> Double
distance} -> Double
distance) (\s :: Step
s@Step' {} Double
a -> Step
s {$sel:distance:Step' :: Double
distance = Double
a} :: Step)

-- | The estimated travel time, in seconds, from the step\'s @StartPosition@
-- to the @EndPosition@. . The travel mode and departure time that you
-- specify in the request determines the calculated time.
step_durationSeconds :: Lens.Lens' Step Prelude.Double
step_durationSeconds :: Lens' Step Double
step_durationSeconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Double
durationSeconds :: Double
$sel:durationSeconds:Step' :: Step -> Double
durationSeconds} -> Double
durationSeconds) (\s :: Step
s@Step' {} Double
a -> Step
s {$sel:durationSeconds:Step' :: Double
durationSeconds = Double
a} :: Step)

-- | The end position of a step. If the position the last step in the leg,
-- this position is the same as the end position of the leg.
step_endPosition :: Lens.Lens' Step (Prelude.NonEmpty Prelude.Double)
step_endPosition :: Lens' Step (NonEmpty Double)
step_endPosition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Sensitive (NonEmpty Double)
endPosition :: Sensitive (NonEmpty Double)
$sel:endPosition:Step' :: Step -> Sensitive (NonEmpty Double)
endPosition} -> Sensitive (NonEmpty Double)
endPosition) (\s :: Step
s@Step' {} Sensitive (NonEmpty Double)
a -> Step
s {$sel:endPosition:Step' :: Sensitive (NonEmpty Double)
endPosition = Sensitive (NonEmpty Double)
a} :: Step) 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 starting position of a step. If the position is the first step in
-- the leg, this position is the same as the start position of the leg.
step_startPosition :: Lens.Lens' Step (Prelude.NonEmpty Prelude.Double)
step_startPosition :: Lens' Step (NonEmpty Double)
step_startPosition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Sensitive (NonEmpty Double)
startPosition :: Sensitive (NonEmpty Double)
$sel:startPosition:Step' :: Step -> Sensitive (NonEmpty Double)
startPosition} -> Sensitive (NonEmpty Double)
startPosition) (\s :: Step
s@Step' {} Sensitive (NonEmpty Double)
a -> Step
s {$sel:startPosition:Step' :: Sensitive (NonEmpty Double)
startPosition = Sensitive (NonEmpty Double)
a} :: Step) 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

instance Data.FromJSON Step where
  parseJSON :: Value -> Parser Step
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Step"
      ( \Object
x ->
          Maybe Natural
-> Double
-> Double
-> Sensitive (NonEmpty Double)
-> Sensitive (NonEmpty Double)
-> Step
Step'
            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
"GeometryOffset")
            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
"Distance")
            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
"DurationSeconds")
            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
"EndPosition")
            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
"StartPosition")
      )

instance Prelude.Hashable Step where
  hashWithSalt :: Int -> Step -> Int
hashWithSalt Int
_salt Step' {Double
Maybe Natural
Sensitive (NonEmpty Double)
startPosition :: Sensitive (NonEmpty Double)
endPosition :: Sensitive (NonEmpty Double)
durationSeconds :: Double
distance :: Double
geometryOffset :: Maybe Natural
$sel:startPosition:Step' :: Step -> Sensitive (NonEmpty Double)
$sel:endPosition:Step' :: Step -> Sensitive (NonEmpty Double)
$sel:durationSeconds:Step' :: Step -> Double
$sel:distance:Step' :: Step -> Double
$sel:geometryOffset:Step' :: Step -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
geometryOffset
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
distance
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
durationSeconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive (NonEmpty Double)
endPosition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive (NonEmpty Double)
startPosition

instance Prelude.NFData Step where
  rnf :: Step -> ()
rnf Step' {Double
Maybe Natural
Sensitive (NonEmpty Double)
startPosition :: Sensitive (NonEmpty Double)
endPosition :: Sensitive (NonEmpty Double)
durationSeconds :: Double
distance :: Double
geometryOffset :: Maybe Natural
$sel:startPosition:Step' :: Step -> Sensitive (NonEmpty Double)
$sel:endPosition:Step' :: Step -> Sensitive (NonEmpty Double)
$sel:durationSeconds:Step' :: Step -> Double
$sel:distance:Step' :: Step -> Double
$sel:geometryOffset:Step' :: Step -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
geometryOffset
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Double
distance
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Double
durationSeconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive (NonEmpty Double)
endPosition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive (NonEmpty Double)
startPosition