{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module Proof.Assistant.State where

import Control.Concurrent.STM (TBQueue, newTBQueueIO)

import Proof.Assistant.Request (InterpreterRequest)
import Proof.Assistant.Settings

-- | Simple state with settings and queue as communication model between bot and backend. 
data InterpreterState settings = InterpreterState
  { InterpreterState settings -> settings
settings :: !settings
  , InterpreterState settings -> TBQueue InterpreterRequest
input    :: !(TBQueue InterpreterRequest)
  }

-- | Initialise a state based on its settings.
newInterpreterState
  :: forall settings. ToInterpreterState settings => settings -> IO (InterpreterState settings)
newInterpreterState :: settings -> IO (InterpreterState settings)
newInterpreterState settings
settings = do
  TBQueue InterpreterRequest
input <- Natural -> IO (TBQueue InterpreterRequest)
forall a. Natural -> IO (TBQueue a)
newTBQueueIO (settings -> Natural
forall settings. ToInterpreterState settings => settings -> Natural
getQueueSize settings
settings)
  InterpreterState settings -> IO (InterpreterState settings)
forall (f :: * -> *) a. Applicative f => a -> f a
pure InterpreterState :: forall settings.
settings -> TBQueue InterpreterRequest -> InterpreterState settings
InterpreterState{settings
TBQueue InterpreterRequest
input :: TBQueue InterpreterRequest
settings :: settings
input :: TBQueue InterpreterRequest
settings :: settings
..}