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
(Geo -> Geo -> Bool) -> (Geo -> Geo -> Bool) -> Eq Geo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Geo -> Geo -> Bool
== :: Geo -> Geo -> Bool
$c/= :: Geo -> Geo -> Bool
/= :: Geo -> Geo -> Bool
Eq, Int -> Geo -> ShowS
[Geo] -> ShowS
Geo -> String
(Int -> Geo -> ShowS)
-> (Geo -> String) -> ([Geo] -> ShowS) -> Show Geo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Geo -> ShowS
showsPrec :: Int -> Geo -> ShowS
$cshow :: Geo -> String
show :: Geo -> String
$cshowList :: [Geo] -> ShowS
showList :: [Geo] -> ShowS
Show)

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