{-# Language FlexibleContexts #-}

module GitHUD.Types (
  OutputConfig(..)
  , buildOutputConfig
  , Prompt
  , TerminalState
  , ShellOutput
  , askShell
  , askRepoState
  , askConfig
  ) where

import Control.Monad.Reader (Reader, MonadReader, asks)
import Control.Monad.Writer (WriterT)

import GitHUD.Config.Types
import GitHUD.Git.Types
import GitHUD.Terminal.Types

data OutputConfig = OutputConfig {
  OutputConfig -> Shell
_shell :: Shell
  , OutputConfig -> GitRepoState
_repoState :: GitRepoState
  , OutputConfig -> Config
_config :: Config
}

buildOutputConfig :: Shell
                  -> GitRepoState
                  -> Config
                  -> OutputConfig
buildOutputConfig :: Shell -> GitRepoState -> Config -> OutputConfig
buildOutputConfig Shell
shell GitRepoState
repoState Config
config = OutputConfig :: Shell -> GitRepoState -> Config -> OutputConfig
OutputConfig {
  _shell :: Shell
_shell = Shell
shell
  , _repoState :: GitRepoState
_repoState = GitRepoState
repoState
  , _config :: Config
_config = Config
config
}

askShell :: MonadReader OutputConfig m => m Shell
askShell :: m Shell
askShell = (OutputConfig -> Shell) -> m Shell
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks OutputConfig -> Shell
_shell

askRepoState :: MonadReader OutputConfig m => m GitRepoState
askRepoState :: m GitRepoState
askRepoState = (OutputConfig -> GitRepoState) -> m GitRepoState
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks OutputConfig -> GitRepoState
_repoState

askConfig :: MonadReader OutputConfig m => m Config
askConfig :: m Config
askConfig = (OutputConfig -> Config) -> m Config
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks OutputConfig -> Config
_config

type Prompt = String

type TerminalState = Reader OutputConfig String

type ShellOutput = WriterT Prompt (Reader OutputConfig) ()