{-# LANGUAGE GADTs #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Haskell.Debug.Adapter.State.Shutdown where

import Control.Monad.IO.Class
import Control.Monad.Except
import qualified System.Log.Logger as L

import Haskell.Debug.Adapter.Type
import Haskell.Debug.Adapter.Utility
import Haskell.Debug.Adapter.Constant


-- |
--
instance AppStateIF ShutdownStateData where
  -- |
  --
  entryAction :: AppState ShutdownStateData -> AppContext ()
entryAction AppState ShutdownStateData
ShutdownState = do
    IO () -> AppContext ()
forall a. IO a -> StateT AppStores (ExceptT ErrMsg IO) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> AppContext ()) -> IO () -> AppContext ()
forall a b. (a -> b) -> a -> b
$ ErrMsg -> ErrMsg -> IO ()
L.debugM ErrMsg
_LOG_APP ErrMsg
"ShutdownState entryAction called."

    Event -> AppContext ()
addEvent Event
CriticalExitEvent

    () -> AppContext ()
forall a. a -> StateT AppStores (ExceptT ErrMsg IO) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()


  -- |
  --
  exitAction :: AppState ShutdownStateData -> AppContext ()
exitAction AppState ShutdownStateData
ShutdownState = do
    let msg :: ErrMsg
msg = ErrMsg
"ShutdownState exitAction must not be called."
    ErrMsg -> AppContext ()
forall a. ErrMsg -> StateT AppStores (ExceptT ErrMsg IO) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ErrMsg
msg


  -- |
  --
  doActivity :: AppState ShutdownStateData
-> WrapRequest -> AppContext (Maybe StateTransit)
doActivity AppState ShutdownStateData
ShutdownState WrapRequest
_ = do
    let msg :: ErrMsg
msg = ErrMsg
"ShutdownState does not support any request."
    ErrMsg -> ErrMsg -> AppContext ()
infoEV ErrMsg
_LOG_APP ErrMsg
msg
    Maybe StateTransit -> AppContext (Maybe StateTransit)
forall a. a -> StateT AppStores (ExceptT ErrMsg IO) a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe StateTransit
forall a. Maybe a
Nothing