using System;
using Server;

namespace Server.Misc
{
	public class FindByName
	{
		public static void Initialize()
		{
			Server.Commands.CommandSystem.Register( "FindByName", AccessLevel.Administrator, new Server.Commands.CommandEventHandler( FindByName_OnCommand ) );
		}

		[Usage( "FindByName <name>" )]
		[Description( "Finds an item by name." )]
		public static void FindByName_OnCommand( Server.Commands.CommandEventArgs e )
		{
			if ( e.Length == 1 )
			{
				string name = e.GetString( 0 ).ToLower();

				foreach ( Item item in World.Items.Values )
				{
					if ( item.Name != null && item.Name.ToLower().IndexOf( name ) >= 0 )
					{
						object root = item.RootParent;

						if ( root is Mobile )
							e.Mobile.SendAsciiMessage( "{0} [{1}]: {2} ({3})", item.GetWorldLocation(), item.Map, root.GetType().Name, ((Mobile)root).Name );
						else
							e.Mobile.SendAsciiMessage( "{0} [{1}]: {2}", item.GetWorldLocation(), item.Map, root==null ? "(null)" : root.GetType().Name );
					}
				}
			}
			else
			{
				e.Mobile.SendAsciiMessage( "Format: FindByName <name>" );
			}
		}
	}
}