-- | Query logging types for observability.
module Database.Bolty.Logging
  ( QueryLog(..)
  ) where

import           Data.Int                (Int64)
import           Data.Kind               (Type)
import qualified Data.HashMap.Lazy       as H
import qualified Data.Text               as T
import           Data.PackStream.Ps      (Ps)


-- | Information about a completed query, passed to the 'queryLogger' callback.
type QueryLog :: Type
data QueryLog = QueryLog
  { QueryLog -> Text
qlCypher      :: !T.Text
  -- ^ The Cypher query text.
  , QueryLog -> HashMap Text Ps
qlParameters  :: !(H.HashMap T.Text Ps)
  -- ^ The query parameters (empty map if none).
  , QueryLog -> Int
qlRowCount    :: !Int
  -- ^ Number of result records returned.
  -- Server-reported timing
  , QueryLog -> Int64
qlServerFirst :: !Int64
  -- ^ @t_first@: milliseconds until the first record was available on the server.
  , QueryLog -> Int64
qlServerLast  :: !Int64
  -- ^ @t_last@: milliseconds until the last record was consumed on the server.
  -- Client-measured timing
  , QueryLog -> Double
qlClientTime  :: !Double
  -- ^ Wall-clock milliseconds for the full round-trip (RUN send to PULL complete),
  -- measured with 'GHC.Clock.getMonotonicTimeNSec'. Includes network latency,
  -- serialization, and deserialization overhead.
  }
  deriving stock (Int -> QueryLog -> ShowS
[QueryLog] -> ShowS
QueryLog -> String
(Int -> QueryLog -> ShowS)
-> (QueryLog -> String) -> ([QueryLog] -> ShowS) -> Show QueryLog
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> QueryLog -> ShowS
showsPrec :: Int -> QueryLog -> ShowS
$cshow :: QueryLog -> String
show :: QueryLog -> String
$cshowList :: [QueryLog] -> ShowS
showList :: [QueryLog] -> ShowS
Show)