/**
 * Copyright © 2010, Res Interactive, LLC. All Rights Reserved.
 */
package com.tootsville.actions;

import java.math.BigDecimal;

import org.starhope.appius.game.AppiusClaudiusCaecus;
import org.starhope.appius.game.RunCommands;
import org.starhope.appius.game.Zone;
import org.starhope.appius.room.Room;
import org.starhope.appius.user.AbstractUser;
import org.starhope.appius.user.events.ActionHandler;
import org.starhope.appius.user.events.ActionMethod;
import org.starhope.appius.user.events.Quaestor;

/**
 * WRITEME: Document this type.
 * 
 * @author brpocock@star-hope.org
 */
public class GiftsForHighScoresHandler implements RunCommands {
    /**
     * @author brpocock@star-hope.org
     *
     */
    final static class HighScoreGiftHandler implements
    ActionMethod
    {
        /**
         * @see org.starhope.appius.user.events.ActionMethod#acceptAction(org.starhope.appius.room.Room,
         *      org.starhope.appius.user.AbstractUser, java.lang.String,
         *      org.starhope.appius.user.AbstractUser, java.lang.String,
         *      java.lang.Object[])
         */
        @Override
		public boolean acceptAction (
                final Room where,
                final AbstractUser subject,
                final String verb,
                final AbstractUser object,
                final String indirectObject,
                final Object... trailer) {
            GiftsForHighScoresHandler.handleScoreEvent (
                    where, subject, verb, object,
                    indirectObject, trailer);
			return true;
        }
    }
	
	/**
	 * WRITEME: Document this method brpocock@star-hope.org
	 * 
	 * @param room WRITEME
	 * @param player WRITEME
	 * @param verb WRITEME
	 * @param object WRITEME
	 * @param eventTypeMoniker WRITEME
	 * @param more WRITEME
	 */
    public static void handleScoreEvent (final Room room,
            final AbstractUser player, final String verb,
            final AbstractUser object, final String eventTypeMoniker,
            final Object [] more) {
        if (more.length < 2) {
            throw new IllegalArgumentException ();
        }
        if (null == more [0] || ! (more [0] instanceof BigDecimal)) {
            throw new IllegalArgumentException ();
        }
        if (null == more [1] || ! (more [1] instanceof Integer)) {
            throw new IllegalArgumentException ();
        }
        ((Integer) more [1]).intValue ();
    }

    /**
     * WRITEME: Document this method brpocock@star-hope.org
     */
    public static void register () {
        // No op
    }

    /**
     * @see org.starhope.appius.game.RunCommands#newZone(org.starhope.appius.game.Zone)
     */
    @Override
	public void newZone (final Zone z) {
        // no op
    }

    /**
     * @see org.starhope.appius.game.RunCommands#run()
     */
    @Override
	public void run () {
        try {
            Quaestor.listen (new ActionHandler (null, null,
                    "event.gotHighScore", null,
                    new HighScoreGiftHandler ()));
        } catch (final Exception e) {
            AppiusClaudiusCaecus.reportBug (e);
        }

    }
}
