{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE StrictData                 #-}

module Network.Tox.TimedT where

import           Control.Monad.IO.Class               (MonadIO)
import           Control.Monad.Reader                 (ReaderT, ask, runReaderT)
import           Control.Monad.State                  (MonadState)
import           Control.Monad.Trans                  (MonadTrans)
import           Control.Monad.Writer                 (MonadWriter)

import           Network.Tox.Crypto.Keyed             (Keyed)
import           Network.Tox.Network.MonadRandomBytes (MonadRandomBytes)
import           Network.Tox.Network.Networked        (Networked)
import           Network.Tox.Time                     (Timestamp)
import           Network.Tox.Timed                    (Timed (..))

newtype TimedT m a = TimedT (ReaderT Timestamp m a)
  deriving (Applicative (TimedT m)
a -> TimedT m a
Applicative (TimedT m)
-> (forall a b. TimedT m a -> (a -> TimedT m b) -> TimedT m b)
-> (forall a b. TimedT m a -> TimedT m b -> TimedT m b)
-> (forall a. a -> TimedT m a)
-> Monad (TimedT m)
TimedT m a -> (a -> TimedT m b) -> TimedT m b
TimedT m a -> TimedT m b -> TimedT m b
forall a. a -> TimedT m a
forall a b. TimedT m a -> TimedT m b -> TimedT m b
forall a b. TimedT m a -> (a -> TimedT m b) -> TimedT m b
forall (m :: * -> *). Monad m => Applicative (TimedT m)
forall (m :: * -> *) a. Monad m => a -> TimedT m a
forall (m :: * -> *) a b.
Monad m =>
TimedT m a -> TimedT m b -> TimedT m b
forall (m :: * -> *) a b.
Monad m =>
TimedT m a -> (a -> TimedT m b) -> TimedT m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> TimedT m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> TimedT m a
>> :: TimedT m a -> TimedT m b -> TimedT m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
TimedT m a -> TimedT m b -> TimedT m b
>>= :: TimedT m a -> (a -> TimedT m b) -> TimedT m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
TimedT m a -> (a -> TimedT m b) -> TimedT m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (TimedT m)
Monad, Functor (TimedT m)
a -> TimedT m a
Functor (TimedT m)
-> (forall a. a -> TimedT m a)
-> (forall a b. TimedT m (a -> b) -> TimedT m a -> TimedT m b)
-> (forall a b c.
    (a -> b -> c) -> TimedT m a -> TimedT m b -> TimedT m c)
-> (forall a b. TimedT m a -> TimedT m b -> TimedT m b)
-> (forall a b. TimedT m a -> TimedT m b -> TimedT m a)
-> Applicative (TimedT m)
TimedT m a -> TimedT m b -> TimedT m b
TimedT m a -> TimedT m b -> TimedT m a
TimedT m (a -> b) -> TimedT m a -> TimedT m b
(a -> b -> c) -> TimedT m a -> TimedT m b -> TimedT m c
forall a. a -> TimedT m a
forall a b. TimedT m a -> TimedT m b -> TimedT m a
forall a b. TimedT m a -> TimedT m b -> TimedT m b
forall a b. TimedT m (a -> b) -> TimedT m a -> TimedT m b
forall a b c.
(a -> b -> c) -> TimedT m a -> TimedT m b -> TimedT m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *). Applicative m => Functor (TimedT m)
forall (m :: * -> *) a. Applicative m => a -> TimedT m a
forall (m :: * -> *) a b.
Applicative m =>
TimedT m a -> TimedT m b -> TimedT m a
forall (m :: * -> *) a b.
Applicative m =>
TimedT m a -> TimedT m b -> TimedT m b
forall (m :: * -> *) a b.
Applicative m =>
TimedT m (a -> b) -> TimedT m a -> TimedT m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> TimedT m a -> TimedT m b -> TimedT m c
<* :: TimedT m a -> TimedT m b -> TimedT m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
TimedT m a -> TimedT m b -> TimedT m a
*> :: TimedT m a -> TimedT m b -> TimedT m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
TimedT m a -> TimedT m b -> TimedT m b
liftA2 :: (a -> b -> c) -> TimedT m a -> TimedT m b -> TimedT m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> TimedT m a -> TimedT m b -> TimedT m c
<*> :: TimedT m (a -> b) -> TimedT m a -> TimedT m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
TimedT m (a -> b) -> TimedT m a -> TimedT m b
pure :: a -> TimedT m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> TimedT m a
$cp1Applicative :: forall (m :: * -> *). Applicative m => Functor (TimedT m)
Applicative, a -> TimedT m b -> TimedT m a
(a -> b) -> TimedT m a -> TimedT m b
(forall a b. (a -> b) -> TimedT m a -> TimedT m b)
-> (forall a b. a -> TimedT m b -> TimedT m a)
-> Functor (TimedT m)
forall a b. a -> TimedT m b -> TimedT m a
forall a b. (a -> b) -> TimedT m a -> TimedT m b
forall (m :: * -> *) a b.
Functor m =>
a -> TimedT m b -> TimedT m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> TimedT m a -> TimedT m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> TimedT m b -> TimedT m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> TimedT m b -> TimedT m a
fmap :: (a -> b) -> TimedT m a -> TimedT m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> TimedT m a -> TimedT m b
Functor, MonadState s, MonadWriter w
    , Monad (TimedT m)
Applicative (TimedT m)
TimedT m KeyPair
Monad (TimedT m)
-> Applicative (TimedT m)
-> (Int -> TimedT m ByteString)
-> TimedT m KeyPair
-> MonadRandomBytes (TimedT m)
Int -> TimedT m ByteString
forall (m :: * -> *).
Monad m
-> Applicative m
-> (Int -> m ByteString)
-> m KeyPair
-> MonadRandomBytes m
forall (m :: * -> *). MonadRandomBytes m => Monad (TimedT m)
forall (m :: * -> *). MonadRandomBytes m => Applicative (TimedT m)
forall (m :: * -> *). MonadRandomBytes m => TimedT m KeyPair
forall (m :: * -> *).
MonadRandomBytes m =>
Int -> TimedT m ByteString
newKeyPair :: TimedT m KeyPair
$cnewKeyPair :: forall (m :: * -> *). MonadRandomBytes m => TimedT m KeyPair
randomBytes :: Int -> TimedT m ByteString
$crandomBytes :: forall (m :: * -> *).
MonadRandomBytes m =>
Int -> TimedT m ByteString
$cp2MonadRandomBytes :: forall (m :: * -> *). MonadRandomBytes m => Applicative (TimedT m)
$cp1MonadRandomBytes :: forall (m :: * -> *). MonadRandomBytes m => Monad (TimedT m)
MonadRandomBytes, m a -> TimedT m a
(forall (m :: * -> *) a. Monad m => m a -> TimedT m a)
-> MonadTrans TimedT
forall (m :: * -> *) a. Monad m => m a -> TimedT m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> TimedT m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> TimedT m a
MonadTrans, Monad (TimedT m)
Monad (TimedT m)
-> (forall a. IO a -> TimedT m a) -> MonadIO (TimedT m)
IO a -> TimedT m a
forall a. IO a -> TimedT m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (TimedT m)
forall (m :: * -> *) a. MonadIO m => IO a -> TimedT m a
liftIO :: IO a -> TimedT m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> TimedT m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (TimedT m)
MonadIO, Monad (TimedT m)
Monad (TimedT m)
-> (forall payload.
    (Binary payload, Show payload) =>
    NodeInfo -> Packet payload -> TimedT m ())
-> Networked (TimedT m)
NodeInfo -> Packet payload -> TimedT m ()
forall payload.
(Binary payload, Show payload) =>
NodeInfo -> Packet payload -> TimedT m ()
forall (m :: * -> *).
Monad m
-> (forall payload.
    (Binary payload, Show payload) =>
    NodeInfo -> Packet payload -> m ())
-> Networked m
forall (m :: * -> *). Networked m => Monad (TimedT m)
forall (m :: * -> *) payload.
(Networked m, Binary payload, Show payload) =>
NodeInfo -> Packet payload -> TimedT m ()
sendPacket :: NodeInfo -> Packet payload -> TimedT m ()
$csendPacket :: forall (m :: * -> *) payload.
(Networked m, Binary payload, Show payload) =>
NodeInfo -> Packet payload -> TimedT m ()
$cp1Networked :: forall (m :: * -> *). Networked m => Monad (TimedT m)
Networked, Monad (TimedT m)
Applicative (TimedT m)
Monad (TimedT m)
-> Applicative (TimedT m)
-> (SecretKey -> PublicKey -> TimedT m CombinedKey)
-> Keyed (TimedT m)
SecretKey -> PublicKey -> TimedT m CombinedKey
forall (m :: * -> *).
Monad m
-> Applicative m
-> (SecretKey -> PublicKey -> m CombinedKey)
-> Keyed m
forall (m :: * -> *). Keyed m => Monad (TimedT m)
forall (m :: * -> *). Keyed m => Applicative (TimedT m)
forall (m :: * -> *).
Keyed m =>
SecretKey -> PublicKey -> TimedT m CombinedKey
getCombinedKey :: SecretKey -> PublicKey -> TimedT m CombinedKey
$cgetCombinedKey :: forall (m :: * -> *).
Keyed m =>
SecretKey -> PublicKey -> TimedT m CombinedKey
$cp2Keyed :: forall (m :: * -> *). Keyed m => Applicative (TimedT m)
$cp1Keyed :: forall (m :: * -> *). Keyed m => Monad (TimedT m)
Keyed)

runTimedT :: TimedT m a -> Timestamp -> m a
runTimedT :: TimedT m a -> Timestamp -> m a
runTimedT (TimedT ReaderT Timestamp m a
m) = ReaderT Timestamp m a -> Timestamp -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT Timestamp m a
m

instance Monad m => Timed (TimedT m) where
  askTime :: TimedT m Timestamp
askTime = ReaderT Timestamp m Timestamp -> TimedT m Timestamp
forall (m :: * -> *) a. ReaderT Timestamp m a -> TimedT m a
TimedT ReaderT Timestamp m Timestamp
forall r (m :: * -> *). MonadReader r m => m r
ask