{-# LANGUAGE DeriveAnyClass  #-}
{-# LANGUAGE DeriveGeneric   #-}
{-# LANGUAGE TemplateHaskell #-}
-------------------------------------------------------------------
-- |
-- Module       : Data.Geospatial.Internal.Geometry.GeoLine
-- Copyright    : (C) 2014-2019 HS-GeoJSON Project
-- License      : BSD-style (see the file LICENSE.md)
-- Maintainer   : Andrew Newman
--
-------------------------------------------------------------------
module Data.Geospatial.Internal.Geometry.GeoLine (
    -- * Type
        GeoLine(..)
    -- * Lenses
    ,   unGeoLine
    ) where

import           Data.Geospatial.Internal.BasicTypes
import           Data.Geospatial.Internal.Geometry.Aeson
import           Data.LineString

import           Control.DeepSeq
import           Control.Lens                            (makeLenses)
import           Control.Monad                           (mzero)
import           Data.Aeson                              (FromJSON (..),
                                                          ToJSON (..),
                                                          Value (..))
import           GHC.Generics                            (Generic)

newtype GeoLine = GeoLine { GeoLine -> LineString GeoPositionWithoutCRS
_unGeoLine :: LineString GeoPositionWithoutCRS } deriving (Int -> GeoLine -> ShowS
[GeoLine] -> ShowS
GeoLine -> String
(Int -> GeoLine -> ShowS)
-> (GeoLine -> String) -> ([GeoLine] -> ShowS) -> Show GeoLine
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GeoLine] -> ShowS
$cshowList :: [GeoLine] -> ShowS
show :: GeoLine -> String
$cshow :: GeoLine -> String
showsPrec :: Int -> GeoLine -> ShowS
$cshowsPrec :: Int -> GeoLine -> ShowS
Show, GeoLine -> GeoLine -> Bool
(GeoLine -> GeoLine -> Bool)
-> (GeoLine -> GeoLine -> Bool) -> Eq GeoLine
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GeoLine -> GeoLine -> Bool
$c/= :: GeoLine -> GeoLine -> Bool
== :: GeoLine -> GeoLine -> Bool
$c== :: GeoLine -> GeoLine -> Bool
Eq, (forall x. GeoLine -> Rep GeoLine x)
-> (forall x. Rep GeoLine x -> GeoLine) -> Generic GeoLine
forall x. Rep GeoLine x -> GeoLine
forall x. GeoLine -> Rep GeoLine x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GeoLine x -> GeoLine
$cfrom :: forall x. GeoLine -> Rep GeoLine x
Generic, GeoLine -> ()
(GeoLine -> ()) -> NFData GeoLine
forall a. (a -> ()) -> NFData a
rnf :: GeoLine -> ()
$crnf :: GeoLine -> ()
NFData)

makeLenses ''GeoLine

-- instances

instance ToJSON GeoLine where
--  toJSON :: a -> Value
    toJSON :: GeoLine -> Value
toJSON = String -> LineString GeoPositionWithoutCRS -> Value
forall a. ToJSON a => String -> a -> Value
makeGeometryGeoAeson String
"LineString" (LineString GeoPositionWithoutCRS -> Value)
-> (GeoLine -> LineString GeoPositionWithoutCRS)
-> GeoLine
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GeoLine -> LineString GeoPositionWithoutCRS
_unGeoLine

instance FromJSON GeoLine where
--  parseJSON :: Value -> Parser a
    parseJSON :: Value -> Parser GeoLine
parseJSON (Object Object
o) = String
-> (LineString GeoPositionWithoutCRS -> GeoLine)
-> Object
-> Parser GeoLine
forall a b.
(FromJSON a, FromJSON b) =>
String -> (a -> b) -> Object -> Parser b
readGeometryGeoAeson String
"LineString" LineString GeoPositionWithoutCRS -> GeoLine
GeoLine Object
o
    parseJSON Value
_          = Parser GeoLine
forall (m :: * -> *) a. MonadPlus m => m a
mzero