module Patrol.Type.Context where

import qualified Data.Aeson as Aeson
import qualified Data.Map as Map
import qualified Data.Text as Text
import qualified Patrol.Type.AppContext as AppContext
import qualified Patrol.Type.BrowserContext as BrowserContext
import qualified Patrol.Type.DeviceContext as DeviceContext
import qualified Patrol.Type.GpuContext as GpuContext
import qualified Patrol.Type.OsContext as OsContext
import qualified Patrol.Type.RuntimeContext as RuntimeContext
import qualified Patrol.Type.TraceContext as TraceContext

data Context
  = App AppContext.AppContext
  | Browser BrowserContext.BrowserContext
  | Device DeviceContext.DeviceContext
  | Gpu GpuContext.GpuContext
  | Os OsContext.OsContext
  | Runtime RuntimeContext.RuntimeContext
  | Trace TraceContext.TraceContext
  | Other (Map.Map Text.Text Aeson.Value)
  deriving (Context -> Context -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Context -> Context -> Bool
$c/= :: Context -> Context -> Bool
== :: Context -> Context -> Bool
$c== :: Context -> Context -> Bool
Eq, Int -> Context -> ShowS
[Context] -> ShowS
Context -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Context] -> ShowS
$cshowList :: [Context] -> ShowS
show :: Context -> String
$cshow :: Context -> String
showsPrec :: Int -> Context -> ShowS
$cshowsPrec :: Int -> Context -> ShowS
Show)

instance Aeson.ToJSON Context where
  toJSON :: Context -> Value
toJSON Context
context = case Context
context of
    App AppContext
appContext -> forall a. ToJSON a => a -> Value
Aeson.toJSON AppContext
appContext
    Browser BrowserContext
browserContext -> forall a. ToJSON a => a -> Value
Aeson.toJSON BrowserContext
browserContext
    Device DeviceContext
deviceContext -> forall a. ToJSON a => a -> Value
Aeson.toJSON DeviceContext
deviceContext
    Gpu GpuContext
gpuContext -> forall a. ToJSON a => a -> Value
Aeson.toJSON GpuContext
gpuContext
    Os OsContext
osContext -> forall a. ToJSON a => a -> Value
Aeson.toJSON OsContext
osContext
    Runtime RuntimeContext
runtimeContext -> forall a. ToJSON a => a -> Value
Aeson.toJSON RuntimeContext
runtimeContext
    Trace TraceContext
traceContext -> forall a. ToJSON a => a -> Value
Aeson.toJSON TraceContext
traceContext
    Other Map Text Value
other -> forall a. ToJSON a => a -> Value
Aeson.toJSON Map Text Value
other