-- |Data type that attaches a time stamp to a 'Report'.
module Ribosome.Host.Data.StoredReport where

import qualified Chronos
import Polysemy.Chronos (ChronosTime)
import qualified Time

import Ribosome.Host.Data.Report (Report)

-- |Data type that attaches a time stamp to a 'Report'.
data StoredReport =
  StoredReport {
    StoredReport -> Report
report :: !Report,
    StoredReport -> Time
time :: !Chronos.Time
  }
  deriving stock (Int -> StoredReport -> ShowS
[StoredReport] -> ShowS
StoredReport -> String
(Int -> StoredReport -> ShowS)
-> (StoredReport -> String)
-> ([StoredReport] -> ShowS)
-> Show StoredReport
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StoredReport] -> ShowS
$cshowList :: [StoredReport] -> ShowS
show :: StoredReport -> String
$cshow :: StoredReport -> String
showsPrec :: Int -> StoredReport -> ShowS
$cshowsPrec :: Int -> StoredReport -> ShowS
Show)

-- |Create a new 'StoredReport' by querying the current time from 'ChronosTime'.
now ::
  Member ChronosTime r =>
  Report ->
  Sem r StoredReport
now :: forall (r :: EffectRow).
Member ChronosTime r =>
Report -> Sem r StoredReport
now Report
r =
  Report -> Time -> StoredReport
StoredReport Report
r (Time -> StoredReport) -> Sem r Time -> Sem r StoredReport
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sem r Time
forall t d (r :: EffectRow). Member (Time t d) r => Sem r t
Time.now