using System;
using Server.Items;

namespace Server.Items
{
	[Flipable]
	public class LeatherGloves : BaseArmor, IArcaneEquip
	{
		public override int BasePhysicalResistance { get { return 2; } }
		public override int BaseFireResistance { get { return 4; } }
		public override int BaseColdResistance { get { return 3; } }
		public override int BasePoisonResistance { get { return 3; } }
		public override int BaseEnergyResistance { get { return 3; } }

		public override int InitMinHits { get { return 30; } }
		public override int InitMaxHits { get { return 40; } }

		public override int StrengthReq { get { return 20; } }

		public override ArmorMaterialType MaterialType { get { return ArmorMaterialType.Leather; } }
		public override CraftResource DefaultResource { get { return CraftResource.RegularLeather; } }

		[Constructable]
		public LeatherGloves()
			: base( 0x13C6 )
		{
			Weight = 1.0;
		}

		public LeatherGloves( Serial serial )
			: base( serial )
		{
		}

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

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

			if ( IsArcane )
			{
				writer.Write( true );
				writer.Write( (int) m_CurArcaneCharges );
				writer.Write( (int) m_MaxArcaneCharges );
			}
			else
			{
				writer.Write( false );
			}
		}

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

			int version = reader.ReadInt();

			switch ( version )
			{
				case 1:
					{
						if ( reader.ReadBool() )
						{
							m_CurArcaneCharges = reader.ReadInt();
							m_MaxArcaneCharges = reader.ReadInt();

							if ( Hue == 2118 )
							{
								Hue = ArcaneGem.DefaultArcaneHue;
							}
						}

						break;
					}
			}
		}

		#region Arcane Impl
		private int m_MaxArcaneCharges, m_CurArcaneCharges;

		[CommandProperty( AccessLevel.GameMaster )]
		public int MaxArcaneCharges
		{
			get { return m_MaxArcaneCharges; }
			set
			{
				m_MaxArcaneCharges = value;
				InvalidateProperties();
				Update();
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int CurArcaneCharges
		{
			get { return m_CurArcaneCharges; }
			set
			{
				m_CurArcaneCharges = value;
				InvalidateProperties();
				Update();
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public bool IsArcane { get { return ( m_MaxArcaneCharges > 0 && m_CurArcaneCharges >= 0 ); } }

		public void Update()
		{
			if ( IsArcane )
			{
				ItemID = 0x26B0;
			}
			else if ( ItemID == 0x26B0 )
			{
				ItemID = 0x13C6;
			}

			if ( IsArcane && CurArcaneCharges == 0 )
			{
				Hue = 0;
			}
		}

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

			if ( IsArcane )
			{
				list.Add( 1061837, "{0}\t{1}", m_CurArcaneCharges, m_MaxArcaneCharges ); // arcane charges: ~1_val~ / ~2_val~
			}
		}

		public void Flip()
		{
			if ( ItemID == 0x13C6 )
			{
				ItemID = 0x13CE;
			}
			else if ( ItemID == 0x13CE )
			{
				ItemID = 0x13C6;
			}
		}
		#endregion
	}
}
