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

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

-- | Describes a location.
--
-- /See:/ 'newLocation' smart constructor.
data Location = Location'
  { -- | The latitude.
    Location -> Maybe Text
latitude :: Prelude.Maybe Prelude.Text,
    -- | The physical address.
    Location -> Maybe Text
address :: Prelude.Maybe Prelude.Text,
    -- | The longitude.
    Location -> Maybe Text
longitude :: Prelude.Maybe Prelude.Text
  }
  deriving (Location -> Location -> Bool
(Location -> Location -> Bool)
-> (Location -> Location -> Bool) -> Eq Location
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, Int -> Location -> ShowS
[Location] -> ShowS
Location -> String
(Int -> Location -> ShowS)
-> (Location -> String) -> ([Location] -> ShowS) -> Show Location
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. Location -> Rep Location x)
-> (forall x. Rep Location x -> Location) -> Generic Location
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.
--
-- 'address', 'location_address' - The physical address.
--
-- 'longitude', 'location_longitude' - The longitude.
newLocation ::
  Location
newLocation :: Location
newLocation =
  Location' :: Maybe Text -> Maybe Text -> Maybe Text -> Location
Location'
    { $sel:latitude:Location' :: Maybe Text
latitude = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:address:Location' :: Maybe Text
address = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:longitude:Location' :: Maybe Text
longitude = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

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

-- | The physical address.
location_address :: Lens.Lens' Location (Prelude.Maybe Prelude.Text)
location_address :: (Maybe Text -> f (Maybe Text)) -> Location -> f Location
location_address = (Location -> Maybe Text)
-> (Location -> Maybe Text -> Location)
-> Lens Location Location (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Location' {Maybe Text
address :: Maybe Text
$sel:address:Location' :: Location -> Maybe Text
address} -> Maybe Text
address) (\s :: Location
s@Location' {} Maybe Text
a -> Location
s {$sel:address:Location' :: Maybe Text
address = Maybe Text
a} :: Location)

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

instance Core.FromJSON Location where
  parseJSON :: Value -> Parser Location
parseJSON =
    String -> (Object -> Parser Location) -> Value -> Parser Location
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Location"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Text -> Location
Location'
            (Maybe Text -> Maybe Text -> Maybe Text -> Location)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Location)
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
"Latitude")
            Parser (Maybe Text -> Maybe Text -> Location)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Location)
forall (f :: * -> *) a b. Applicative f => 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
"Address")
            Parser (Maybe Text -> Location)
-> Parser (Maybe Text) -> Parser Location
forall (f :: * -> *) a b. Applicative f => 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
"Longitude")
      )

instance Prelude.Hashable Location

instance Prelude.NFData Location

instance Core.ToJSON Location where
  toJSON :: Location -> Value
toJSON Location' {Maybe Text
longitude :: Maybe Text
address :: Maybe Text
latitude :: Maybe Text
$sel:longitude:Location' :: Location -> Maybe Text
$sel:address:Location' :: Location -> Maybe Text
$sel:latitude:Location' :: Location -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Latitude" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
latitude,
            (Text
"Address" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
address,
            (Text
"Longitude" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
longitude
          ]
      )