import { Events, ActivityType, Client } from "discord.js"; // Import base Client type
import logger from "../utils/logger"; // Use default import
import { initializeShoukaku } from "../structures/ShoukakuEvents"; // Import the correct setup function
import { BotClient } from "../index"; // Import BotClient type

export default {
  // Use export default
  name: Events.ClientReady,
  once: true, // This event should only run once
  async execute(_client: BotClient) {
    // Use BotClient type
    // Ensure _client.user is available
    if (!_client.user) {
      logger.error("Client user is not available on ready event.");
      return;
    }
    logger.info(`Ready! Logged in as ${_client.user.tag}`);

    // Initialize the Shoukaku instance and attach listeners
    try {
      // Assign the initialized Shoukaku instance to _client.shoukaku
      _client.shoukaku = initializeShoukaku(_client);
      logger.info("Shoukaku instance initialized successfully"); // Log message adjusted slightly
    } catch (error: unknown) {
      // Type caught error
      const errorMsg = error instanceof Error ? error.message : String(error);
      logger.error(`Failed to initialize Shoukaku: ${errorMsg}`);
      // Depending on the severity, you might want to exit or handle this differently
    }

    // Set activity status
    _client.user.setActivity("Music | /play", { type: ActivityType.Listening });
  },
};
