{-# LANGUAGE TemplateHaskell #-}

-- | A command handler
module CalamityCommands.Handler (CommandHandler (..)) where

import CalamityCommands.AliasType
import CalamityCommands.Command
import CalamityCommands.Group
import Data.HashMap.Lazy qualified as LH
import Data.Text qualified as S
import Optics.TH
import TextShow qualified
import TextShow.TH (deriveTextShow)

data CommandHandler m c a = CommandHandler
  { forall (m :: * -> *) c a.
CommandHandler m c a -> HashMap Text (Group m c a, AliasType)
groups :: LH.HashMap S.Text (Group m c a, AliasType)
  -- ^ Top level groups
  , forall (m :: * -> *) c a.
CommandHandler m c a -> HashMap Text (Command m c a, AliasType)
commands :: LH.HashMap S.Text (Command m c a, AliasType)
  -- ^ Top level commands
  }

data CommandHandlerS m c a = CommandHandlerS
  { forall (m :: * -> *) c a.
CommandHandlerS m c a -> [(Text, (Group m c a, AliasType))]
groups :: [(S.Text, (Group m c a, AliasType))]
  , forall (m :: * -> *) c a.
CommandHandlerS m c a -> [(Text, (Command m c a, AliasType))]
commands :: [(S.Text, (Command m c a, AliasType))]
  }
  deriving (Int -> CommandHandlerS m c a -> ShowS
[CommandHandlerS m c a] -> ShowS
CommandHandlerS m c a -> String
(Int -> CommandHandlerS m c a -> ShowS)
-> (CommandHandlerS m c a -> String)
-> ([CommandHandlerS m c a] -> ShowS)
-> Show (CommandHandlerS m c a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (m :: * -> *) c a.
(Show a, Show c) =>
Int -> CommandHandlerS m c a -> ShowS
forall (m :: * -> *) c a.
(Show a, Show c) =>
[CommandHandlerS m c a] -> ShowS
forall (m :: * -> *) c a.
(Show a, Show c) =>
CommandHandlerS m c a -> String
$cshowsPrec :: forall (m :: * -> *) c a.
(Show a, Show c) =>
Int -> CommandHandlerS m c a -> ShowS
showsPrec :: Int -> CommandHandlerS m c a -> ShowS
$cshow :: forall (m :: * -> *) c a.
(Show a, Show c) =>
CommandHandlerS m c a -> String
show :: CommandHandlerS m c a -> String
$cshowList :: forall (m :: * -> *) c a.
(Show a, Show c) =>
[CommandHandlerS m c a] -> ShowS
showList :: [CommandHandlerS m c a] -> ShowS
Show)

instance (Show c, Show a) => Show (CommandHandler m c a) where
  showsPrec :: Int -> CommandHandler m c a -> ShowS
showsPrec Int
d CommandHandler {HashMap Text (Group m c a, AliasType)
$sel:groups:CommandHandler :: forall (m :: * -> *) c a.
CommandHandler m c a -> HashMap Text (Group m c a, AliasType)
groups :: HashMap Text (Group m c a, AliasType)
groups, HashMap Text (Command m c a, AliasType)
$sel:commands:CommandHandler :: forall (m :: * -> *) c a.
CommandHandler m c a -> HashMap Text (Command m c a, AliasType)
commands :: HashMap Text (Command m c a, AliasType)
commands} = Int -> CommandHandlerS m c a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
d (CommandHandlerS m c a -> ShowS) -> CommandHandlerS m c a -> ShowS
forall a b. (a -> b) -> a -> b
$ [(Text, (Group m c a, AliasType))]
-> [(Text, (Command m c a, AliasType))] -> CommandHandlerS m c a
forall (m :: * -> *) c a.
[(Text, (Group m c a, AliasType))]
-> [(Text, (Command m c a, AliasType))] -> CommandHandlerS m c a
CommandHandlerS (HashMap Text (Group m c a, AliasType)
-> [(Text, (Group m c a, AliasType))]
forall k v. HashMap k v -> [(k, v)]
LH.toList HashMap Text (Group m c a, AliasType)
groups) (HashMap Text (Command m c a, AliasType)
-> [(Text, (Command m c a, AliasType))]
forall k v. HashMap k v -> [(k, v)]
LH.toList HashMap Text (Command m c a, AliasType)
commands)

$(deriveTextShow ''CommandHandlerS)

instance (TextShow.TextShow c, TextShow.TextShow a) => TextShow.TextShow (CommandHandler m c a) where
  showbPrec :: Int -> CommandHandler m c a -> Builder
showbPrec Int
d CommandHandler {HashMap Text (Group m c a, AliasType)
$sel:groups:CommandHandler :: forall (m :: * -> *) c a.
CommandHandler m c a -> HashMap Text (Group m c a, AliasType)
groups :: HashMap Text (Group m c a, AliasType)
groups, HashMap Text (Command m c a, AliasType)
$sel:commands:CommandHandler :: forall (m :: * -> *) c a.
CommandHandler m c a -> HashMap Text (Command m c a, AliasType)
commands :: HashMap Text (Command m c a, AliasType)
commands} = Int -> CommandHandlerS m c a -> Builder
forall a. TextShow a => Int -> a -> Builder
TextShow.showbPrec Int
d (CommandHandlerS m c a -> Builder)
-> CommandHandlerS m c a -> Builder
forall a b. (a -> b) -> a -> b
$ [(Text, (Group m c a, AliasType))]
-> [(Text, (Command m c a, AliasType))] -> CommandHandlerS m c a
forall (m :: * -> *) c a.
[(Text, (Group m c a, AliasType))]
-> [(Text, (Command m c a, AliasType))] -> CommandHandlerS m c a
CommandHandlerS (HashMap Text (Group m c a, AliasType)
-> [(Text, (Group m c a, AliasType))]
forall k v. HashMap k v -> [(k, v)]
LH.toList HashMap Text (Group m c a, AliasType)
groups) (HashMap Text (Command m c a, AliasType)
-> [(Text, (Command m c a, AliasType))]
forall k v. HashMap k v -> [(k, v)]
LH.toList HashMap Text (Command m c a, AliasType)
commands)

$(makeFieldLabelsNoPrefix ''CommandHandler)