module Patrol.Type.Breadcrumb where

import qualified Data.Aeson as Aeson
import qualified Data.Map as Map
import qualified Data.Text as Text
import qualified Data.Time as Time
import qualified Patrol.Extra.Aeson as Aeson
import qualified Patrol.Type.BreadcrumbType as BreadcrumbType
import qualified Patrol.Type.EventId as EventId
import qualified Patrol.Type.Level as Level

-- | <https://develop.sentry.dev/sdk/event-payloads/types/#breadcrumb>
data Breadcrumb = Breadcrumb
  { Breadcrumb -> Text
category :: Text.Text,
    Breadcrumb -> Map Text Value
data_ :: Map.Map Text.Text Aeson.Value,
    Breadcrumb -> Maybe EventId
eventId :: Maybe EventId.EventId,
    Breadcrumb -> Maybe Level
level :: Maybe Level.Level,
    Breadcrumb -> Text
message :: Text.Text,
    Breadcrumb -> Maybe UTCTime
timestamp :: Maybe Time.UTCTime,
    Breadcrumb -> Maybe BreadcrumbType
type_ :: Maybe BreadcrumbType.BreadcrumbType
  }
  deriving (Breadcrumb -> Breadcrumb -> Bool
(Breadcrumb -> Breadcrumb -> Bool)
-> (Breadcrumb -> Breadcrumb -> Bool) -> Eq Breadcrumb
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Breadcrumb -> Breadcrumb -> Bool
== :: Breadcrumb -> Breadcrumb -> Bool
$c/= :: Breadcrumb -> Breadcrumb -> Bool
/= :: Breadcrumb -> Breadcrumb -> Bool
Eq, Int -> Breadcrumb -> ShowS
[Breadcrumb] -> ShowS
Breadcrumb -> String
(Int -> Breadcrumb -> ShowS)
-> (Breadcrumb -> String)
-> ([Breadcrumb] -> ShowS)
-> Show Breadcrumb
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Breadcrumb -> ShowS
showsPrec :: Int -> Breadcrumb -> ShowS
$cshow :: Breadcrumb -> String
show :: Breadcrumb -> String
$cshowList :: [Breadcrumb] -> ShowS
showList :: [Breadcrumb] -> ShowS
Show)

instance Aeson.ToJSON Breadcrumb where
  toJSON :: Breadcrumb -> Value
toJSON Breadcrumb
breadcrumb =
    [Pair] -> Value
Aeson.intoObject
      [ String -> Text -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"category" (Text -> Pair) -> Text -> Pair
forall a b. (a -> b) -> a -> b
$ Breadcrumb -> Text
category Breadcrumb
breadcrumb,
        String -> Map Text Value -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"data" (Map Text Value -> Pair) -> Map Text Value -> Pair
forall a b. (a -> b) -> a -> b
$ Breadcrumb -> Map Text Value
data_ Breadcrumb
breadcrumb,
        String -> Maybe EventId -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"event_id" (Maybe EventId -> Pair) -> Maybe EventId -> Pair
forall a b. (a -> b) -> a -> b
$ Breadcrumb -> Maybe EventId
eventId Breadcrumb
breadcrumb,
        String -> Maybe Level -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"level" (Maybe Level -> Pair) -> Maybe Level -> Pair
forall a b. (a -> b) -> a -> b
$ Breadcrumb -> Maybe Level
level Breadcrumb
breadcrumb,
        String -> Text -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"message" (Text -> Pair) -> Text -> Pair
forall a b. (a -> b) -> a -> b
$ Breadcrumb -> Text
message Breadcrumb
breadcrumb,
        String -> Maybe UTCTime -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"timestamp" (Maybe UTCTime -> Pair) -> Maybe UTCTime -> Pair
forall a b. (a -> b) -> a -> b
$ Breadcrumb -> Maybe UTCTime
timestamp Breadcrumb
breadcrumb,
        String -> Maybe BreadcrumbType -> Pair
forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"type" (Maybe BreadcrumbType -> Pair) -> Maybe BreadcrumbType -> Pair
forall a b. (a -> b) -> a -> b
$ Breadcrumb -> Maybe BreadcrumbType
type_ Breadcrumb
breadcrumb
      ]

empty :: Breadcrumb
empty :: Breadcrumb
empty =
  Breadcrumb
    { category :: Text
category = Text
Text.empty,
      data_ :: Map Text Value
data_ = Map Text Value
forall k a. Map k a
Map.empty,
      eventId :: Maybe EventId
eventId = Maybe EventId
forall a. Maybe a
Nothing,
      level :: Maybe Level
level = Maybe Level
forall a. Maybe a
Nothing,
      message :: Text
message = Text
Text.empty,
      timestamp :: Maybe UTCTime
timestamp = Maybe UTCTime
forall a. Maybe a
Nothing,
      type_ :: Maybe BreadcrumbType
type_ = Maybe BreadcrumbType
forall a. Maybe a
Nothing
    }