{-# 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.SecurityHub.Types.GeoLocation
-- 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.SecurityHub.Types.GeoLocation where

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

-- | Provides the latitude and longitude coordinates of a location.
--
-- /See:/ 'newGeoLocation' smart constructor.
data GeoLocation = GeoLocation'
  { -- | The latitude of the location.
    GeoLocation -> Maybe Double
lat :: Prelude.Maybe Prelude.Double,
    -- | The longitude of the location.
    GeoLocation -> Maybe Double
lon :: Prelude.Maybe Prelude.Double
  }
  deriving (GeoLocation -> GeoLocation -> Bool
(GeoLocation -> GeoLocation -> Bool)
-> (GeoLocation -> GeoLocation -> Bool) -> Eq GeoLocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeoLocation -> GeoLocation -> Bool
$c/= :: GeoLocation -> GeoLocation -> Bool
== :: GeoLocation -> GeoLocation -> Bool
$c== :: GeoLocation -> GeoLocation -> Bool
Prelude.Eq, ReadPrec [GeoLocation]
ReadPrec GeoLocation
Int -> ReadS GeoLocation
ReadS [GeoLocation]
(Int -> ReadS GeoLocation)
-> ReadS [GeoLocation]
-> ReadPrec GeoLocation
-> ReadPrec [GeoLocation]
-> Read GeoLocation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GeoLocation]
$creadListPrec :: ReadPrec [GeoLocation]
readPrec :: ReadPrec GeoLocation
$creadPrec :: ReadPrec GeoLocation
readList :: ReadS [GeoLocation]
$creadList :: ReadS [GeoLocation]
readsPrec :: Int -> ReadS GeoLocation
$creadsPrec :: Int -> ReadS GeoLocation
Prelude.Read, Int -> GeoLocation -> ShowS
[GeoLocation] -> ShowS
GeoLocation -> String
(Int -> GeoLocation -> ShowS)
-> (GeoLocation -> String)
-> ([GeoLocation] -> ShowS)
-> Show GeoLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeoLocation] -> ShowS
$cshowList :: [GeoLocation] -> ShowS
show :: GeoLocation -> String
$cshow :: GeoLocation -> String
showsPrec :: Int -> GeoLocation -> ShowS
$cshowsPrec :: Int -> GeoLocation -> ShowS
Prelude.Show, (forall x. GeoLocation -> Rep GeoLocation x)
-> (forall x. Rep GeoLocation x -> GeoLocation)
-> Generic GeoLocation
forall x. Rep GeoLocation x -> GeoLocation
forall x. GeoLocation -> Rep GeoLocation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GeoLocation x -> GeoLocation
$cfrom :: forall x. GeoLocation -> Rep GeoLocation x
Prelude.Generic)

-- |
-- Create a value of 'GeoLocation' 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:
--
-- 'lat', 'geoLocation_lat' - The latitude of the location.
--
-- 'lon', 'geoLocation_lon' - The longitude of the location.
newGeoLocation ::
  GeoLocation
newGeoLocation :: GeoLocation
newGeoLocation =
  GeoLocation' :: Maybe Double -> Maybe Double -> GeoLocation
GeoLocation'
    { $sel:lat:GeoLocation' :: Maybe Double
lat = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:lon:GeoLocation' :: Maybe Double
lon = Maybe Double
forall a. Maybe a
Prelude.Nothing
    }

-- | The latitude of the location.
geoLocation_lat :: Lens.Lens' GeoLocation (Prelude.Maybe Prelude.Double)
geoLocation_lat :: (Maybe Double -> f (Maybe Double)) -> GeoLocation -> f GeoLocation
geoLocation_lat = (GeoLocation -> Maybe Double)
-> (GeoLocation -> Maybe Double -> GeoLocation)
-> Lens GeoLocation GeoLocation (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GeoLocation' {Maybe Double
lat :: Maybe Double
$sel:lat:GeoLocation' :: GeoLocation -> Maybe Double
lat} -> Maybe Double
lat) (\s :: GeoLocation
s@GeoLocation' {} Maybe Double
a -> GeoLocation
s {$sel:lat:GeoLocation' :: Maybe Double
lat = Maybe Double
a} :: GeoLocation)

-- | The longitude of the location.
geoLocation_lon :: Lens.Lens' GeoLocation (Prelude.Maybe Prelude.Double)
geoLocation_lon :: (Maybe Double -> f (Maybe Double)) -> GeoLocation -> f GeoLocation
geoLocation_lon = (GeoLocation -> Maybe Double)
-> (GeoLocation -> Maybe Double -> GeoLocation)
-> Lens GeoLocation GeoLocation (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GeoLocation' {Maybe Double
lon :: Maybe Double
$sel:lon:GeoLocation' :: GeoLocation -> Maybe Double
lon} -> Maybe Double
lon) (\s :: GeoLocation
s@GeoLocation' {} Maybe Double
a -> GeoLocation
s {$sel:lon:GeoLocation' :: Maybe Double
lon = Maybe Double
a} :: GeoLocation)

instance Core.FromJSON GeoLocation where
  parseJSON :: Value -> Parser GeoLocation
parseJSON =
    String
-> (Object -> Parser GeoLocation) -> Value -> Parser GeoLocation
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GeoLocation"
      ( \Object
x ->
          Maybe Double -> Maybe Double -> GeoLocation
GeoLocation'
            (Maybe Double -> Maybe Double -> GeoLocation)
-> Parser (Maybe Double) -> Parser (Maybe Double -> GeoLocation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Lat") Parser (Maybe Double -> GeoLocation)
-> Parser (Maybe Double) -> Parser GeoLocation
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Lon")
      )

instance Prelude.Hashable GeoLocation

instance Prelude.NFData GeoLocation

instance Core.ToJSON GeoLocation where
  toJSON :: GeoLocation -> Value
toJSON GeoLocation' {Maybe Double
lon :: Maybe Double
lat :: Maybe Double
$sel:lon:GeoLocation' :: GeoLocation -> Maybe Double
$sel:lat:GeoLocation' :: GeoLocation -> Maybe Double
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Lat" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
lat,
            (Text
"Lon" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
lon
          ]
      )