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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Location.Types.Circle
import qualified Amazonka.Prelude as Prelude

-- | Contains the geofence geometry details.
--
-- A geofence geometry is made up of either a polygon or a circle. Can be
-- either a polygon or a circle. Including both will return a validation
-- error.
--
-- Amazon Location doesn\'t currently support polygons with holes,
-- multipolygons, polygons that are wound clockwise, or that cross the
-- antimeridian.
--
-- /See:/ 'newGeofenceGeometry' smart constructor.
data GeofenceGeometry = GeofenceGeometry'
  { -- | A circle on the earth, as defined by a center point and a radius.
    GeofenceGeometry -> Maybe (Sensitive Circle)
circle :: Prelude.Maybe (Data.Sensitive Circle),
    -- | A polygon is a list of linear rings which are each made up of a list of
    -- vertices.
    --
    -- Each vertex is a 2-dimensional point of the form:
    -- @[longitude, latitude]@. This is represented as an array of doubles of
    -- length 2 (so @[double, double]@).
    --
    -- An array of 4 or more vertices, where the first and last vertex are the
    -- same (to form a closed boundary), is called a linear ring. The linear
    -- ring vertices must be listed in counter-clockwise order around the
    -- ring’s interior. The linear ring is represented as an array of vertices,
    -- or an array of arrays of doubles (@[[double, double], ...]@).
    --
    -- A geofence consists of a single linear ring. To allow for future
    -- expansion, the Polygon parameter takes an array of linear rings, which
    -- is represented as an array of arrays of arrays of doubles
    -- (@[[[double, double], ...], ...]@).
    --
    -- A linear ring for use in geofences can consist of between 4 and 1,000
    -- vertices.
    GeofenceGeometry
-> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon :: Prelude.Maybe (Prelude.NonEmpty (Prelude.NonEmpty (Data.Sensitive (Prelude.NonEmpty Prelude.Double))))
  }
  deriving (GeofenceGeometry -> GeofenceGeometry -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeofenceGeometry -> GeofenceGeometry -> Bool
$c/= :: GeofenceGeometry -> GeofenceGeometry -> Bool
== :: GeofenceGeometry -> GeofenceGeometry -> Bool
$c== :: GeofenceGeometry -> GeofenceGeometry -> Bool
Prelude.Eq, Int -> GeofenceGeometry -> ShowS
[GeofenceGeometry] -> ShowS
GeofenceGeometry -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeofenceGeometry] -> ShowS
$cshowList :: [GeofenceGeometry] -> ShowS
show :: GeofenceGeometry -> String
$cshow :: GeofenceGeometry -> String
showsPrec :: Int -> GeofenceGeometry -> ShowS
$cshowsPrec :: Int -> GeofenceGeometry -> ShowS
Prelude.Show, forall x. Rep GeofenceGeometry x -> GeofenceGeometry
forall x. GeofenceGeometry -> Rep GeofenceGeometry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GeofenceGeometry x -> GeofenceGeometry
$cfrom :: forall x. GeofenceGeometry -> Rep GeofenceGeometry x
Prelude.Generic)

-- |
-- Create a value of 'GeofenceGeometry' 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:
--
-- 'circle', 'geofenceGeometry_circle' - A circle on the earth, as defined by a center point and a radius.
--
-- 'polygon', 'geofenceGeometry_polygon' - A polygon is a list of linear rings which are each made up of a list of
-- vertices.
--
-- Each vertex is a 2-dimensional point of the form:
-- @[longitude, latitude]@. This is represented as an array of doubles of
-- length 2 (so @[double, double]@).
--
-- An array of 4 or more vertices, where the first and last vertex are the
-- same (to form a closed boundary), is called a linear ring. The linear
-- ring vertices must be listed in counter-clockwise order around the
-- ring’s interior. The linear ring is represented as an array of vertices,
-- or an array of arrays of doubles (@[[double, double], ...]@).
--
-- A geofence consists of a single linear ring. To allow for future
-- expansion, the Polygon parameter takes an array of linear rings, which
-- is represented as an array of arrays of arrays of doubles
-- (@[[[double, double], ...], ...]@).
--
-- A linear ring for use in geofences can consist of between 4 and 1,000
-- vertices.
newGeofenceGeometry ::
  GeofenceGeometry
newGeofenceGeometry :: GeofenceGeometry
newGeofenceGeometry =
  GeofenceGeometry'
    { $sel:circle:GeofenceGeometry' :: Maybe (Sensitive Circle)
circle = forall a. Maybe a
Prelude.Nothing,
      $sel:polygon:GeofenceGeometry' :: Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon = forall a. Maybe a
Prelude.Nothing
    }

-- | A circle on the earth, as defined by a center point and a radius.
geofenceGeometry_circle :: Lens.Lens' GeofenceGeometry (Prelude.Maybe Circle)
geofenceGeometry_circle :: Lens' GeofenceGeometry (Maybe Circle)
geofenceGeometry_circle = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GeofenceGeometry' {Maybe (Sensitive Circle)
circle :: Maybe (Sensitive Circle)
$sel:circle:GeofenceGeometry' :: GeofenceGeometry -> Maybe (Sensitive Circle)
circle} -> Maybe (Sensitive Circle)
circle) (\s :: GeofenceGeometry
s@GeofenceGeometry' {} Maybe (Sensitive Circle)
a -> GeofenceGeometry
s {$sel:circle:GeofenceGeometry' :: Maybe (Sensitive Circle)
circle = Maybe (Sensitive Circle)
a} :: GeofenceGeometry) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | A polygon is a list of linear rings which are each made up of a list of
-- vertices.
--
-- Each vertex is a 2-dimensional point of the form:
-- @[longitude, latitude]@. This is represented as an array of doubles of
-- length 2 (so @[double, double]@).
--
-- An array of 4 or more vertices, where the first and last vertex are the
-- same (to form a closed boundary), is called a linear ring. The linear
-- ring vertices must be listed in counter-clockwise order around the
-- ring’s interior. The linear ring is represented as an array of vertices,
-- or an array of arrays of doubles (@[[double, double], ...]@).
--
-- A geofence consists of a single linear ring. To allow for future
-- expansion, the Polygon parameter takes an array of linear rings, which
-- is represented as an array of arrays of arrays of doubles
-- (@[[[double, double], ...], ...]@).
--
-- A linear ring for use in geofences can consist of between 4 and 1,000
-- vertices.
geofenceGeometry_polygon :: Lens.Lens' GeofenceGeometry (Prelude.Maybe (Prelude.NonEmpty (Prelude.NonEmpty (Prelude.NonEmpty Prelude.Double))))
geofenceGeometry_polygon :: Lens'
  GeofenceGeometry (Maybe (NonEmpty (NonEmpty (NonEmpty Double))))
geofenceGeometry_polygon = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GeofenceGeometry' {Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon :: Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
$sel:polygon:GeofenceGeometry' :: GeofenceGeometry
-> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon} -> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon) (\s :: GeofenceGeometry
s@GeofenceGeometry' {} Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
a -> GeofenceGeometry
s {$sel:polygon:GeofenceGeometry' :: Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon = Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
a} :: GeofenceGeometry) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON GeofenceGeometry where
  parseJSON :: Value -> Parser GeofenceGeometry
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"GeofenceGeometry"
      ( \Object
x ->
          Maybe (Sensitive Circle)
-> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
-> GeofenceGeometry
GeofenceGeometry'
            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
"Circle")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Polygon")
      )

instance Prelude.Hashable GeofenceGeometry where
  hashWithSalt :: Int -> GeofenceGeometry -> Int
hashWithSalt Int
_salt GeofenceGeometry' {Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
Maybe (Sensitive Circle)
polygon :: Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
circle :: Maybe (Sensitive Circle)
$sel:polygon:GeofenceGeometry' :: GeofenceGeometry
-> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
$sel:circle:GeofenceGeometry' :: GeofenceGeometry -> Maybe (Sensitive Circle)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Circle)
circle
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon

instance Prelude.NFData GeofenceGeometry where
  rnf :: GeofenceGeometry -> ()
rnf GeofenceGeometry' {Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
Maybe (Sensitive Circle)
polygon :: Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
circle :: Maybe (Sensitive Circle)
$sel:polygon:GeofenceGeometry' :: GeofenceGeometry
-> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
$sel:circle:GeofenceGeometry' :: GeofenceGeometry -> Maybe (Sensitive Circle)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Circle)
circle
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon

instance Data.ToJSON GeofenceGeometry where
  toJSON :: GeofenceGeometry -> Value
toJSON GeofenceGeometry' {Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
Maybe (Sensitive Circle)
polygon :: Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
circle :: Maybe (Sensitive Circle)
$sel:polygon:GeofenceGeometry' :: GeofenceGeometry
-> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
$sel:circle:GeofenceGeometry' :: GeofenceGeometry -> Maybe (Sensitive Circle)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Circle" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive Circle)
circle,
            (Key
"Polygon" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon
          ]
      )