{-# LANGUAGE UndecidableInstances #-}

-- | Internal module for logging types.
module Shrun.Logging.Types.Internal
  ( FileLog (..),
    ConsoleLog (..),
    LogMode (..),
  )
where

import Shrun.Prelude

-- | 'FileLog' is a textual representation of a given log after it has
-- been formatted. No coloring is included, but we include the prefix
-- (e.g. Warn) along with a timestamp.
newtype FileLog = UnsafeFileLog
  { FileLog -> Text
unFileLog :: Text
  }
  deriving stock (FileLog -> FileLog -> Bool
(FileLog -> FileLog -> Bool)
-> (FileLog -> FileLog -> Bool) -> Eq FileLog
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FileLog -> FileLog -> Bool
== :: FileLog -> FileLog -> Bool
$c/= :: FileLog -> FileLog -> Bool
/= :: FileLog -> FileLog -> Bool
Eq, Int -> FileLog -> ShowS
[FileLog] -> ShowS
FileLog -> String
(Int -> FileLog -> ShowS)
-> (FileLog -> String) -> ([FileLog] -> ShowS) -> Show FileLog
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FileLog -> ShowS
showsPrec :: Int -> FileLog -> ShowS
$cshow :: FileLog -> String
show :: FileLog -> String
$cshowList :: [FileLog] -> ShowS
showList :: [FileLog] -> ShowS
Show)

instance
  ( k ~ A_Getter,
    a ~ Text,
    b ~ Text
  ) =>
  LabelOptic "unFileLog" k FileLog FileLog a b
  where
  labelOptic :: Optic k NoIx FileLog FileLog a b
labelOptic = (FileLog -> a) -> Getter FileLog a
forall s a. (s -> a) -> Getter s a
to (\(UnsafeFileLog Text
x) -> a
Text
x)
  {-# INLINE labelOptic #-}

-- | 'ConsoleLog' is a textual representation of a given log after it has
-- been formatted.
newtype ConsoleLog = UnsafeConsoleLog
  { ConsoleLog -> Text
unConsoleLog :: Text
  }
  deriving stock (ConsoleLog -> ConsoleLog -> Bool
(ConsoleLog -> ConsoleLog -> Bool)
-> (ConsoleLog -> ConsoleLog -> Bool) -> Eq ConsoleLog
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConsoleLog -> ConsoleLog -> Bool
== :: ConsoleLog -> ConsoleLog -> Bool
$c/= :: ConsoleLog -> ConsoleLog -> Bool
/= :: ConsoleLog -> ConsoleLog -> Bool
Eq, Int -> ConsoleLog -> ShowS
[ConsoleLog] -> ShowS
ConsoleLog -> String
(Int -> ConsoleLog -> ShowS)
-> (ConsoleLog -> String)
-> ([ConsoleLog] -> ShowS)
-> Show ConsoleLog
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConsoleLog -> ShowS
showsPrec :: Int -> ConsoleLog -> ShowS
$cshow :: ConsoleLog -> String
show :: ConsoleLog -> String
$cshowList :: [ConsoleLog] -> ShowS
showList :: [ConsoleLog] -> ShowS
Show)

instance
  ( k ~ A_Getter,
    a ~ Text,
    b ~ Text
  ) =>
  LabelOptic "unConsoleLog" k ConsoleLog ConsoleLog a b
  where
  labelOptic :: Optic k NoIx ConsoleLog ConsoleLog a b
labelOptic = (ConsoleLog -> a) -> Getter ConsoleLog a
forall s a. (s -> a) -> Getter s a
to (\(UnsafeConsoleLog Text
x) -> a
Text
x)
  {-# INLINE labelOptic #-}

-- NOTE: LogMode exists here so we do not have cyclic dependencies w/
-- RegionLogger

-- | Determines the logging behavior. This option only affects console logs;
-- File logs are unaffected.
data LogMode
  = -- | Sets the logging region to this log.
    LogModeSet
  | -- | Appends the log to the logging region.
    LogModeAppend
  | -- | Closes the logging region, finishing with the log.
    LogModeFinish
  deriving stock (LogMode
LogMode -> LogMode -> Bounded LogMode
forall a. a -> a -> Bounded a
$cminBound :: LogMode
minBound :: LogMode
$cmaxBound :: LogMode
maxBound :: LogMode
Bounded, Int -> LogMode
LogMode -> Int
LogMode -> [LogMode]
LogMode -> LogMode
LogMode -> LogMode -> [LogMode]
LogMode -> LogMode -> LogMode -> [LogMode]
(LogMode -> LogMode)
-> (LogMode -> LogMode)
-> (Int -> LogMode)
-> (LogMode -> Int)
-> (LogMode -> [LogMode])
-> (LogMode -> LogMode -> [LogMode])
-> (LogMode -> LogMode -> [LogMode])
-> (LogMode -> LogMode -> LogMode -> [LogMode])
-> Enum LogMode
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: LogMode -> LogMode
succ :: LogMode -> LogMode
$cpred :: LogMode -> LogMode
pred :: LogMode -> LogMode
$ctoEnum :: Int -> LogMode
toEnum :: Int -> LogMode
$cfromEnum :: LogMode -> Int
fromEnum :: LogMode -> Int
$cenumFrom :: LogMode -> [LogMode]
enumFrom :: LogMode -> [LogMode]
$cenumFromThen :: LogMode -> LogMode -> [LogMode]
enumFromThen :: LogMode -> LogMode -> [LogMode]
$cenumFromTo :: LogMode -> LogMode -> [LogMode]
enumFromTo :: LogMode -> LogMode -> [LogMode]
$cenumFromThenTo :: LogMode -> LogMode -> LogMode -> [LogMode]
enumFromThenTo :: LogMode -> LogMode -> LogMode -> [LogMode]
Enum, LogMode -> LogMode -> Bool
(LogMode -> LogMode -> Bool)
-> (LogMode -> LogMode -> Bool) -> Eq LogMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LogMode -> LogMode -> Bool
== :: LogMode -> LogMode -> Bool
$c/= :: LogMode -> LogMode -> Bool
/= :: LogMode -> LogMode -> Bool
Eq, Int -> LogMode -> ShowS
[LogMode] -> ShowS
LogMode -> String
(Int -> LogMode -> ShowS)
-> (LogMode -> String) -> ([LogMode] -> ShowS) -> Show LogMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LogMode -> ShowS
showsPrec :: Int -> LogMode -> ShowS
$cshow :: LogMode -> String
show :: LogMode -> String
$cshowList :: [LogMode] -> ShowS
showList :: [LogMode] -> ShowS
Show)