{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}

module IAFinance.Environment.Network(
    Has,
    EnvNetwork,
    Network(..),
    Manager,
    get
) where

-----------------------------------------------------------------------------
-- import

import Control.Concurrent.Async.Lifted.Safe ()
import Control.Monad.Reader (MonadReader, MonadIO, ask, liftIO)
import Control.Concurrent.STM (readTVarIO)
import Network.HTTP.Conduit (Manager)

import IAFinance.Environment.Internal (Has(..), EnvNetwork, Network(..))
import IAFinance.Environment ()

-----------------------------------------------------------------------------
-- Network

get :: (Has EnvNetwork env, MonadReader env m, MonadIO m)
    => m Network
get = ask >>= \env -> io $ readTVarIO $ member env

-- helper

io :: (MonadIO m) => IO a -> m a
io = liftIO
