{-# 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.DeviceFarm.Types.Location
-- 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.DeviceFarm.Types.Location 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 a latitude and longitude pair, expressed in geographic
-- coordinate system degrees (for example, 47.6204, -122.3491).
--
-- Elevation is currently not supported.
--
-- /See:/ 'newLocation' smart constructor.
data Location = Location'
  { -- | The latitude.
    Location -> Double
latitude :: Prelude.Double,
    -- | The longitude.
    Location -> Double
longitude :: Prelude.Double
  }
  deriving (Location -> Location -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Location -> Location -> Bool
$c/= :: Location -> Location -> Bool
== :: Location -> Location -> Bool
$c== :: Location -> Location -> Bool
Prelude.Eq, ReadPrec [Location]
ReadPrec Location
Int -> ReadS Location
ReadS [Location]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Location]
$creadListPrec :: ReadPrec [Location]
readPrec :: ReadPrec Location
$creadPrec :: ReadPrec Location
readList :: ReadS [Location]
$creadList :: ReadS [Location]
readsPrec :: Int -> ReadS Location
$creadsPrec :: Int -> ReadS Location
Prelude.Read, Int -> Location -> ShowS
[Location] -> ShowS
Location -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Location] -> ShowS
$cshowList :: [Location] -> ShowS
show :: Location -> String
$cshow :: Location -> String
showsPrec :: Int -> Location -> ShowS
$cshowsPrec :: Int -> Location -> ShowS
Prelude.Show, forall x. Rep Location x -> Location
forall x. Location -> Rep Location x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Location x -> Location
$cfrom :: forall x. Location -> Rep Location x
Prelude.Generic)

-- |
-- Create a value of 'Location' 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:
--
-- 'latitude', 'location_latitude' - The latitude.
--
-- 'longitude', 'location_longitude' - The longitude.
newLocation ::
  -- | 'latitude'
  Prelude.Double ->
  -- | 'longitude'
  Prelude.Double ->
  Location
newLocation :: Double -> Double -> Location
newLocation Double
pLatitude_ Double
pLongitude_ =
  Location'
    { $sel:latitude:Location' :: Double
latitude = Double
pLatitude_,
      $sel:longitude:Location' :: Double
longitude = Double
pLongitude_
    }

-- | The latitude.
location_latitude :: Lens.Lens' Location Prelude.Double
location_latitude :: Lens' Location Double
location_latitude = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Location' {Double
latitude :: Double
$sel:latitude:Location' :: Location -> Double
latitude} -> Double
latitude) (\s :: Location
s@Location' {} Double
a -> Location
s {$sel:latitude:Location' :: Double
latitude = Double
a} :: Location)

-- | The longitude.
location_longitude :: Lens.Lens' Location Prelude.Double
location_longitude :: Lens' Location Double
location_longitude = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Location' {Double
longitude :: Double
$sel:longitude:Location' :: Location -> Double
longitude} -> Double
longitude) (\s :: Location
s@Location' {} Double
a -> Location
s {$sel:longitude:Location' :: Double
longitude = Double
a} :: Location)

instance Data.FromJSON Location where
  parseJSON :: Value -> Parser Location
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Location"
      ( \Object
x ->
          Double -> Double -> Location
Location'
            forall (f :: * -> *) a b. Functor 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 Location where
  hashWithSalt :: Int -> Location -> Int
hashWithSalt Int
_salt Location' {Double
longitude :: Double
latitude :: Double
$sel:longitude:Location' :: Location -> Double
$sel:latitude:Location' :: Location -> Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
latitude
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
longitude

instance Prelude.NFData Location where
  rnf :: Location -> ()
rnf Location' {Double
longitude :: Double
latitude :: Double
$sel:longitude:Location' :: Location -> Double
$sel:latitude:Location' :: Location -> Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Double
latitude
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Double
longitude

instance Data.ToJSON Location where
  toJSON :: Location -> Value
toJSON Location' {Double
longitude :: Double
latitude :: Double
$sel:longitude:Location' :: Location -> Double
$sel:latitude:Location' :: Location -> Double
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"latitude" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Double
latitude),
            forall a. a -> Maybe a
Prelude.Just (Key
"longitude" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Double
longitude)
          ]
      )