using System;
using Server.Items;
using Server.Misc;

namespace Server.Items
{
	public class WoodBoard : Item, IAxe
	{
		private CraftResource m_Resource;

		[CommandProperty( AccessLevel.GameMaster )]
		public CraftResource Resource
		{
			get { return m_Resource; }
			set { m_Resource = value; InvalidateProperties(); }
		}

		[Constructable]
		public WoodBoard() : this( 1 )
		{
		}

		[Constructable]
		public WoodBoard( int amount ) : this( CraftResource.Wooden, amount )
		{
		}

		[Constructable]
		public WoodBoard( CraftResource resource ): this( resource, 1 )
		{
		}

		[Constructable]
		public WoodBoard( CraftResource resource, int amount ): base( 0x1BD7 )
		{
			Stackable = true;
			Weight = 1.0;
			Name = "wood";
			Amount = amount;
			m_Resource = resource;
		}

		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );

			if ( !CraftResources.IsStandard( m_Resource ) )
			{
				int num = CraftResources.GetLocalizationNumber( m_Resource );

				if ( num > 0 )
					list.Add( num );
				else
					list.Add( CraftResources.GetName( m_Resource ) );
			}
		}
		public WoodBoard( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 1 ); // version

			writer.Write( (int)m_Resource );
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();

			switch ( version )
			{
				case 1:
					{
						m_Resource = (CraftResource)reader.ReadInt();
						break;
					}
			}

			if ( version == 0 )
				m_Resource = CraftResource.Wooden;
		}

		public virtual bool TryCreateBoards( Mobile from, double skill, Item item )
		{
			if ( Deleted || !from.CanSee( this ) ) 
				return false;
			else if ( Server.Misc.SkillCheck.TradeSkill( from, Trades.Carpentry, false ) < skill && Server.Misc.SkillCheck.TradeSkill( from, Trades.Lumberjacking, false ) < skill )
			{
				item.Delete();
				from.SendLocalizedMessage( 1072652 ); // You cannot work this strange and unusual wood.
				return false;
			}
			base.ScissorHelper( from, item, 1, false );
			return true;
		}

		public virtual bool Axe( Mobile from, BaseAxe axe )
		{
			if ( ItemID != 0x1BD7 )
			{
				ItemID = 0x1BD7;
				Weight = 1.0;
				return true;
			}
			
			return false;
		}
	}
}