withChoice :: Monad m => [CardID] -> (CardID -> StateT GameState m ()) ->
              StateT GameState m()
withChoice cards f = do
  s <- get
  case s^.ioRequest of
    Just (IOReqChooseCard _ (Just card)) -> do
      trace ("Chosen card is " ++ show card) (return ())
      ioRequest .= Nothing
      f card
    _ -> ioRequest .= (Just $ IOReqChooseCard cards Nothing)

-- withColorChoice :: Monad m => (Mana -> StateT GameState m ()) ->
--                    StateT GameState m ()
-- withColorChoice f = do
--   s <- get
--   case s^.ioRequest of
--     Just (IOReqChooseColor (Just color)) -> do
--       ioRequest .= Nothing
--       f color
--     _ -> ioRequest .= (Just $ IOReqChooseColor Nothing)

-- withCardFromLibrary :: Monad m => PlayerID -> CardSelector ->
--                        (CardID -> StateT GameState m ()) ->
--                        StateT GameState m ()
-- withCardFromLibrary pID pred f = do
--   s <- get
--   let cIDWorks :: CardID -> Bool
--       cIDWorks = (`evalState` s) . pred . CardTarget
--       filteredDeck = filter cIDWorks
--                      (s^.playerWithID pID.deck)
--   withChoice filteredDeck f

--------------------------------------------------------------------------------
-- Ability Utility                                                            --
--------------------------------------------------------------------------------
withChoice :: Monad m => [CardID] -> (CardID -> StateT GameState m ()) ->
              StateT GameState m()
withChoice cards f = do
  s <- get
  case s^.ioRequest of
    Just (IOReqChooseCard _ (Just card)) -> do
      trace ("Chosen card is " ++ show card) (return ())
      ioRequest .= Nothing
      f card
    _ -> ioRequest .= (Just $ IOReqChooseCard cards Nothing)

-- withColorChoice :: Monad m => (Mana -> StateT GameState m ()) ->
--                    StateT GameState m ()
-- withColorChoice f = do
--   s <- get
--   case s^.ioRequest of
--     Just (IOReqChooseColor (Just color)) -> do
--       ioRequest .= Nothing
--       f color
--     _ -> ioRequest .= (Just $ IOReqChooseColor Nothing)

-- withCardFromLibrary :: Monad m => PlayerID -> CardSelector ->
--                        (CardID -> StateT GameState m ()) ->
--                        StateT GameState m ()
-- withCardFromLibrary pID pred f = do
--   s <- get
--   let cIDWorks :: CardID -> Bool
--       cIDWorks = (`evalState` s) . pred . CardTarget
--       filteredDeck = filter cIDWorks
--                      (s^.playerWithID pID.deck)
--   withChoice filteredDeck f

--------------------------------------------------------------------------------
-- Ability Utility                                                            --
--------------------------------------------------------------------------------
withChoice cards f = do
  s <- get
  case s^.ioRequest of
    Just (IOReqChooseCard _ (Just card)) -> do
      trace ("Chosen card is " ++ show card) (return ())
      ioRequest .= Nothing
      f card
    _ -> ioRequest .= (Just $ IOReqChooseCard cards Nothing)

-- withColorChoice :: Monad m => (Mana -> StateT GameState m ()) ->
--                    StateT GameState m ()
-- withColorChoice f = do
--   s <- get
--   case s^.ioRequest of
--     Just (IOReqChooseColor (Just color)) -> do
--       ioRequest .= Nothing
--       f color
--     _ -> ioRequest .= (Just $ IOReqChooseColor Nothing)

-- withCardFromLibrary :: Monad m => PlayerID -> CardSelector ->
--                        (CardID -> StateT GameState m ()) ->
--                        StateT GameState m ()
-- withCardFromLibrary pID pred f = do
--   s <- get
--   let cIDWorks :: CardID -> Bool
--       cIDWorks = (`evalState` s) . pred . CardTarget
--       filteredDeck = filter cIDWorks
--                      (s^.playerWithID pID.deck)
--   withChoice filteredDeck f

--------------------------------------------------------------------------------
-- Ability Utility                                                            --
--------------------------------------------------------------------------------