module Patrol.Type.Geo where

import qualified Data.Aeson as Aeson
import qualified Data.Text as Text
import qualified Patrol.Extra.Aeson as Aeson

-- | <https://develop.sentry.dev/sdk/event-payloads/types/#geo>
data Geo = Geo
  { Geo -> Text
city :: Text.Text,
    Geo -> Text
countryCode :: Text.Text,
    Geo -> Text
region :: Text.Text
  }
  deriving (Geo -> Geo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Geo -> Geo -> Bool
$c/= :: Geo -> Geo -> Bool
== :: Geo -> Geo -> Bool
$c== :: Geo -> Geo -> Bool
Eq, Int -> Geo -> ShowS
[Geo] -> ShowS
Geo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Geo] -> ShowS
$cshowList :: [Geo] -> ShowS
show :: Geo -> String
$cshow :: Geo -> String
showsPrec :: Int -> Geo -> ShowS
$cshowsPrec :: Int -> Geo -> ShowS
Show)

instance Aeson.ToJSON Geo where
  toJSON :: Geo -> Value
toJSON Geo
geo =
    [Pair] -> Value
Aeson.intoObject
      [ forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"city" forall a b. (a -> b) -> a -> b
$ Geo -> Text
city Geo
geo,
        forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"country_code" forall a b. (a -> b) -> a -> b
$ Geo -> Text
countryCode Geo
geo,
        forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"region" forall a b. (a -> b) -> a -> b
$ Geo -> Text
region Geo
geo
      ]

empty :: Geo
empty :: Geo
empty =
  Geo
    { city :: Text
city = Text
Text.empty,
      countryCode :: Text
countryCode = Text
Text.empty,
      region :: Text
region = Text
Text.empty
    }