module Data.Geolocation.Reverse.Types where
import Data.Aeson
import Control.Monad (mzero)
import qualified Data.Text as T
import Data.ISO3166_CountryCodes
newtype Latitude = Latitude (Maybe Double)
deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)
newtype Longitude = Longitude (Maybe Double)
deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)
newtype City = City T.Text deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)
newtype Suburb = Suburb T.Text deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)
newtype Street = Street T.Text deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)
newtype Postcode= Postcode T.Text deriving (Eq,Ord,Show,Read,FromJSON,ToJSON)
instance ToJSON CountryCode
instance FromJSON CountryCode where
parseJSON (String t) = return . read . T.unpack . T.toUpper $ t
parseJSON _ = mzero
data ParsedLocationInfo
= ParsedLocationInfo
{ parsedCountry :: CountryCode
, parsedCity :: City
, parsedSuburb :: Maybe Suburb
, parsedStreet :: Maybe Street
, parsedPostCode :: Maybe Postcode
} deriving (Eq,Ord,Show)