-- | The Discord Handle. Holds all the information related to the connection.
module Discord.Handle
  ( DiscordHandle(..)
  , HandleThreadId(..)
  ) where

import Control.Concurrent (ThreadId, Chan, MVar)
import qualified Data.Text as T

import Discord.Internal.Rest (RestChanHandle(..))
import Discord.Internal.Gateway (GatewayHandle(..), CacheHandle(..))

-- | Thread Ids marked by what type they are
data HandleThreadId
  = -- | A Rest API thread
    HandleThreadIdRest ThreadId
  | -- | A cache thread
  HandleThreadIdCache ThreadId
  | -- | A logger thread
  HandleThreadIdLogger ThreadId
  | -- | A gateway thread 
  HandleThreadIdGateway ThreadId

-- | The main Handle structure
data DiscordHandle = DiscordHandle
  { -- | Handle to the Rest loop
    DiscordHandle -> RestChanHandle
discordHandleRestChan :: RestChanHandle
  , -- | Handle to the Websocket gateway event loop
    DiscordHandle -> GatewayHandle
discordHandleGateway :: GatewayHandle
  , -- | Handle to the cache
    DiscordHandle -> CacheHandle
discordHandleCache :: CacheHandle
  , -- | List of the threads currently in use by the library
    DiscordHandle -> [HandleThreadId]
discordHandleThreads :: [HandleThreadId]
  , -- | `Chan` used to send messages to the internal logger
    DiscordHandle -> Chan Text
discordHandleLog :: Chan T.Text
  , -- | `MVar` containing a description of the latest library error
    DiscordHandle -> MVar Text
discordHandleLibraryError :: MVar T.Text
  }