module Patrol.Type.AppContext where

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

-- | <https://develop.sentry.dev/sdk/event-payloads/types/#appcontext>
data AppContext = AppContext
  { AppContext -> Text
appBuild :: Text.Text,
    AppContext -> Text
appIdentifier :: Text.Text,
    AppContext -> Maybe Int
appMemory :: Maybe Int,
    AppContext -> Text
appName :: Text.Text,
    AppContext -> Maybe UTCTime
appStartTime :: Maybe Time.UTCTime,
    AppContext -> Text
appVersion :: Text.Text,
    AppContext -> Text
buildType :: Text.Text,
    AppContext -> Text
deviceAppHash :: Text.Text
  }
  deriving (AppContext -> AppContext -> Bool
(AppContext -> AppContext -> Bool)
-> (AppContext -> AppContext -> Bool) -> Eq AppContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AppContext -> AppContext -> Bool
== :: AppContext -> AppContext -> Bool
$c/= :: AppContext -> AppContext -> Bool
/= :: AppContext -> AppContext -> Bool
Eq, Int -> AppContext -> ShowS
[AppContext] -> ShowS
AppContext -> String
(Int -> AppContext -> ShowS)
-> (AppContext -> String)
-> ([AppContext] -> ShowS)
-> Show AppContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AppContext -> ShowS
showsPrec :: Int -> AppContext -> ShowS
$cshow :: AppContext -> String
show :: AppContext -> String
$cshowList :: [AppContext] -> ShowS
showList :: [AppContext] -> ShowS
Show)

instance Aeson.ToJSON AppContext where
  toJSON :: AppContext -> Value
toJSON AppContext
appContext =
    [Pair] -> Value
Aeson.intoObject
      [ String -> Text -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"app_build" (Text -> Pair) -> Text -> Pair
forall a b. (a -> b) -> a -> b
$ AppContext -> Text
appBuild AppContext
appContext,
        String -> Text -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"app_identifier" (Text -> Pair) -> Text -> Pair
forall a b. (a -> b) -> a -> b
$ AppContext -> Text
appIdentifier AppContext
appContext,
        String -> Maybe Int -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"app_memory" (Maybe Int -> Pair) -> Maybe Int -> Pair
forall a b. (a -> b) -> a -> b
$ AppContext -> Maybe Int
appMemory AppContext
appContext,
        String -> Text -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"app_name" (Text -> Pair) -> Text -> Pair
forall a b. (a -> b) -> a -> b
$ AppContext -> Text
appName AppContext
appContext,
        String -> Maybe UTCTime -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"app_start_time" (Maybe UTCTime -> Pair) -> Maybe UTCTime -> Pair
forall a b. (a -> b) -> a -> b
$ AppContext -> Maybe UTCTime
appStartTime AppContext
appContext,
        String -> Text -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"app_version" (Text -> Pair) -> Text -> Pair
forall a b. (a -> b) -> a -> b
$ AppContext -> Text
appVersion AppContext
appContext,
        String -> Text -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"build_type" (Text -> Pair) -> Text -> Pair
forall a b. (a -> b) -> a -> b
$ AppContext -> Text
buildType AppContext
appContext,
        String -> Text -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"device_app_hash" (Text -> Pair) -> Text -> Pair
forall a b. (a -> b) -> a -> b
$ AppContext -> Text
deviceAppHash AppContext
appContext
      ]

empty :: AppContext
empty :: AppContext
empty =
  AppContext
    { appBuild :: Text
appBuild = Text
Text.empty,
      appIdentifier :: Text
appIdentifier = Text
Text.empty,
      appMemory :: Maybe Int
appMemory = Maybe Int
forall a. Maybe a
Nothing,
      appName :: Text
appName = Text
Text.empty,
      appStartTime :: Maybe UTCTime
appStartTime = Maybe UTCTime
forall a. Maybe a
Nothing,
      appVersion :: Text
appVersion = Text
Text.empty,
      buildType :: Text
buildType = Text
Text.empty,
      deviceAppHash :: Text
deviceAppHash = Text
Text.empty
    }