"""Contains all the cogs that deal with game commands."""
from discord.ext import commands  # Has the cog class
from interactions import cog_ext  # Used for slash commands

from gwendolyn_old.utils import get_params  # pylint: disable=import-error

params = get_params()


class GamesCog(commands.Cog):
  """Contains miscellaneous game commands."""

  def __init__(self, bot):
    """Initialize the cog."""
    self.bot = bot

  @cog_ext.cog_slash(**params["balance"])
  async def balance(self, ctx):
    """Check user balance."""
    await self.bot.money.sendBalance(ctx)

  @cog_ext.cog_slash(**params["give"])
  async def give(self, ctx, user, amount):
    """Give another user an amount of GwendoBucks."""
    await self.bot.money.giveMoney(ctx, user, amount)

  @cog_ext.cog_slash(**params["trivia"])
  async def trivia(self, ctx, answer=""):
    """Run a game of trivia."""
    await self.bot.games.trivia.triviaParse(ctx, answer)


class BlackjackCog(commands.Cog):
  """Contains the blackjack commands."""

  def __init__(self, bot):
    """Initialize the cog."""
    self.bot = bot

  @cog_ext.cog_subcommand(**params["blackjack_start"])
  async def blackjack_start(self, ctx):
    """Start a game of blackjack."""
    await self.bot.games.blackjack.start(ctx)

  @cog_ext.cog_subcommand(**params["blackjack_bet"])
  async def blackjack_bet(self, ctx, bet):
    """Enter the game of blackjack with a bet."""
    await self.bot.games.blackjack.enter_game(ctx, bet)

  @cog_ext.cog_subcommand(**params["blackjack_hilo"])
  async def blackjack_hilo(self, ctx):
    """Get the hilo value for the deck in blackjack."""
    await self.bot.games.blackjack.hilo(ctx)

  @cog_ext.cog_subcommand(**params["blackjack_shuffle"])
  async def blackjack_shuffle(self, ctx):
    """Shuffle the blackjack game."""
    await self.bot.games.blackjack.shuffle(ctx)

  @cog_ext.cog_subcommand(**params["blackjack_cards"])
  async def blackjack_cards(self, ctx):
    """Get the amount of cards left in the blackjack deck."""
    await self.bot.games.blackjack.cards(ctx)


class ConnectFourCog(commands.Cog):
  """Contains all the connect four commands."""

  def __init__(self, bot):
    """Initialize the cog."""
    self.bot = bot

  @cog_ext.cog_subcommand(**params["connect_four_start_user"])
  async def connect_four_start_user(self, ctx, user):
    """Start a game of connect four against another user."""
    await self.bot.games.connect_four.start(ctx, user)

  @cog_ext.cog_subcommand(**params["connect_four_start_gwendolyn"])
  async def connect_four_start_gwendolyn(self, ctx, difficulty=3):
    """Start a game of connect four against Gwendolyn."""
    await self.bot.games.connect_four.start(ctx, difficulty)


class HangmanCog(commands.Cog):
  """Contains all the hangman commands."""

  def __init__(self, bot):
    """Initialize the cog."""
    self.bot = bot

  @cog_ext.cog_slash(**params["hangman"])
  async def hangman(self, ctx):
    """Start a game of hangman."""
    await self.bot.games.hangman.start(ctx)

class WordleCog(commands.Cog):
  """Contains all the wordle commands."""

  def __init__(self, bot):
    """Initialize the cog."""
    self.bot = bot

  @cog_ext.cog_subcommand(**params["wordle_start"])
  async def wordle_start(self, ctx, letters = 5):
    """Start a game of wordle."""
    await self.bot.games.wordle.start(ctx, letters)

  @cog_ext.cog_subcommand(**params["wordle_guess"])
  async def wordle_guess(self, ctx, guess):
    """Start a game of wordle."""
    await self.bot.games.wordle.guess(ctx, guess)


class HexCog(commands.Cog):
  """Contains all the hex commands."""

  def __init__(self, bot):
    """Initialize the cog."""
    self.bot = bot
    self.hex = self.bot.games.hex

  @cog_ext.cog_subcommand(**params["hex_start_user"])
  async def hex_start_user(self, ctx, user):
    """Start a game of hex against another player."""
    await self.hex.start(ctx, user)

  @cog_ext.cog_subcommand(**params["hex_start_gwendolyn"])
  async def hex_start_gwendolyn(self, ctx, difficulty=2):
    """Start a game of hex against Gwendolyn."""
    await self.hex.start(ctx, difficulty)

  @cog_ext.cog_subcommand(**params["hex_place"])
  async def hex_place(self, ctx, coordinates):
    """Place a piece in the hex game."""
    await self.hex.placeHex(ctx, coordinates, f"#{ctx.author.id}")

  @cog_ext.cog_subcommand(**params["hex_undo"])
  async def hex_undo(self, ctx):
    """Undo your last hex move."""
    await self.hex.undo(ctx)

  @cog_ext.cog_subcommand(**params["hex_swap"])
  async def hex_swap(self, ctx):
    """Perform a hex swap."""
    await self.hex.swap(ctx)

  @cog_ext.cog_subcommand(**params["hex_surrender"])
  async def hex_surrender(self, ctx):
    """Surrender the hex game."""
    await self.hex.surrender(ctx)


def setup(bot):
  """Add all the cogs to the bot."""
  bot.add_cog(GamesCog(bot))
  bot.add_cog(BlackjackCog(bot))
  bot.add_cog(ConnectFourCog(bot))
  bot.add_cog(HangmanCog(bot))
  bot.add_cog(HexCog(bot))
  bot.add_cog(WordleCog(bot))
