/*
 * REFERENCE / TEMPLATE ONLY - this is not a maintained integration and is
 * not compiled as part of alnino-bridge (hence the .txt extension).
 *
 * This is a CONCRETE EXAMPLE for aCis-family forks (confirmed working
 * against this IVoiceCommandHandler pattern on several real packs). If your
 * gameserver isn't built this way, see claim-trigger-pseudocode.md in this
 * same folder for the framework-agnostic version - the only thing that
 * actually matters is the one SQL INSERT below.
 */
package net.sf.l2j.gameserver.handler.voicecommandhandlers; // adjust to your pack's package layout

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import net.sf.l2j.commons.logging.CLogger;
import net.sf.l2j.commons.pool.ConnectionPool;

import net.sf.l2j.gameserver.handler.IVoiceCommandHandler;
import net.sf.l2j.gameserver.model.actor.Player;

public class VoiceAlninoClaim implements IVoiceCommandHandler
{
	private static final CLogger LOGGER = new CLogger(VoiceAlninoClaim.class.getName());

	private static final String[] VOICE_COMMANDS = { "claim" };

	// Table name must match database.claimRequestsTable in alnino-bridge's config.yml.
	private static final String INSERT = "INSERT INTO alnino_claim_requests (field_value) VALUES (?);";

	@Override
	public void useVoiceCommand(Player player, String command)
	{
		try (Connection con = ConnectionPool.getConnection();
			PreparedStatement statement = con.prepareStatement(INSERT))
		{
			// Swap for player.getName() if alnino.playerField identifies by character name instead.
			statement.setString(1, player.getAccountName());
			statement.execute();

			player.sendMessage("Checking for donations to claim... check your inventory in a few seconds.");
		}
		catch (SQLException e)
		{
			LOGGER.warn("Failed to queue Alnino claim request for {}: {}", player.getAccountName(), e.getMessage());
			player.sendMessage("Something went wrong, please try again shortly.");
		}
	}

	@Override
	public String[] getVoiceCommandList()
	{
		return VOICE_COMMANDS;
	}
}
