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

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

-- | Contains the geofence geometry details.
--
-- 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'
  { -- | An array of 1 or more linear rings. A linear ring is an array of 4 or
    -- more vertices, where the first and last vertex are the same to form a
    -- closed boundary. Each vertex is a 2-dimensional point of the form:
    -- @[longitude, latitude]@.
    --
    -- The first linear ring is an outer ring, describing the polygon\'s
    -- boundary. Subsequent linear rings may be inner or outer rings to
    -- describe holes and islands. Outer rings must list their vertices in
    -- counter-clockwise order around the ring\'s center, where the left side
    -- is the polygon\'s exterior. Inner rings must list their vertices in
    -- clockwise order, where the left side is the polygon\'s interior.
    GeofenceGeometry
-> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon :: Prelude.Maybe (Prelude.NonEmpty (Prelude.NonEmpty (Core.Sensitive (Prelude.NonEmpty Prelude.Double))))
  }
  deriving (GeofenceGeometry -> GeofenceGeometry -> Bool
(GeofenceGeometry -> GeofenceGeometry -> Bool)
-> (GeofenceGeometry -> GeofenceGeometry -> Bool)
-> Eq GeofenceGeometry
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
(Int -> GeofenceGeometry -> ShowS)
-> (GeofenceGeometry -> String)
-> ([GeofenceGeometry] -> ShowS)
-> Show GeofenceGeometry
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. GeofenceGeometry -> Rep GeofenceGeometry x)
-> (forall x. Rep GeofenceGeometry x -> GeofenceGeometry)
-> Generic GeofenceGeometry
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:
--
-- 'polygon', 'geofenceGeometry_polygon' - An array of 1 or more linear rings. A linear ring is an array of 4 or
-- more vertices, where the first and last vertex are the same to form a
-- closed boundary. Each vertex is a 2-dimensional point of the form:
-- @[longitude, latitude]@.
--
-- The first linear ring is an outer ring, describing the polygon\'s
-- boundary. Subsequent linear rings may be inner or outer rings to
-- describe holes and islands. Outer rings must list their vertices in
-- counter-clockwise order around the ring\'s center, where the left side
-- is the polygon\'s exterior. Inner rings must list their vertices in
-- clockwise order, where the left side is the polygon\'s interior.
newGeofenceGeometry ::
  GeofenceGeometry
newGeofenceGeometry :: GeofenceGeometry
newGeofenceGeometry =
  GeofenceGeometry' :: Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
-> GeofenceGeometry
GeofenceGeometry' {$sel:polygon:GeofenceGeometry' :: Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
polygon = Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
forall a. Maybe a
Prelude.Nothing}

-- | An array of 1 or more linear rings. A linear ring is an array of 4 or
-- more vertices, where the first and last vertex are the same to form a
-- closed boundary. Each vertex is a 2-dimensional point of the form:
-- @[longitude, latitude]@.
--
-- The first linear ring is an outer ring, describing the polygon\'s
-- boundary. Subsequent linear rings may be inner or outer rings to
-- describe holes and islands. Outer rings must list their vertices in
-- counter-clockwise order around the ring\'s center, where the left side
-- is the polygon\'s exterior. Inner rings must list their vertices in
-- clockwise order, where the left side is the polygon\'s interior.
geofenceGeometry_polygon :: Lens.Lens' GeofenceGeometry (Prelude.Maybe (Prelude.NonEmpty (Prelude.NonEmpty (Prelude.NonEmpty Prelude.Double))))
geofenceGeometry_polygon :: (Maybe (NonEmpty (NonEmpty (NonEmpty Double)))
 -> f (Maybe (NonEmpty (NonEmpty (NonEmpty Double)))))
-> GeofenceGeometry -> f GeofenceGeometry
geofenceGeometry_polygon = (GeofenceGeometry
 -> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double)))))
-> (GeofenceGeometry
    -> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
    -> GeofenceGeometry)
-> Lens
     GeofenceGeometry
     GeofenceGeometry
     (Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double)))))
     (Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double)))))
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) ((Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
  -> f (Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))))
 -> GeofenceGeometry -> f GeofenceGeometry)
-> ((Maybe (NonEmpty (NonEmpty (NonEmpty Double)))
     -> f (Maybe (NonEmpty (NonEmpty (NonEmpty Double)))))
    -> Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
    -> f (Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))))
-> (Maybe (NonEmpty (NonEmpty (NonEmpty Double)))
    -> f (Maybe (NonEmpty (NonEmpty (NonEmpty Double)))))
-> GeofenceGeometry
-> f GeofenceGeometry
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
  (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
  (NonEmpty (NonEmpty (NonEmpty Double)))
  (NonEmpty (NonEmpty (NonEmpty Double)))
-> Iso
     (Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double)))))
     (Maybe (NonEmpty (NonEmpty (Sensitive (NonEmpty Double)))))
     (Maybe (NonEmpty (NonEmpty (NonEmpty Double))))
     (Maybe (NonEmpty (NonEmpty (NonEmpty Double))))
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 AnIso
  (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
  (NonEmpty (NonEmpty (Sensitive (NonEmpty Double))))
  (NonEmpty (NonEmpty (NonEmpty Double)))
  (NonEmpty (NonEmpty (NonEmpty Double)))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable GeofenceGeometry

instance Prelude.NFData GeofenceGeometry

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