using System;
using System.Collections.Generic;
using System.Text;


namespace ActionGame.GameResources.Models
{
    public class EnemyDefinition
    {
        public Int32 Key { get; set; }
        public String Name { get; set; }
        public Int32 CharacterSetKey { get; set; }
        public Int32 MovementKey { get; set; }
        public Int32 AttackKey { get; set; }
        public Double AttackSpeed { get; set; }
        public Int32 Health { get; set; }
        public Int32 Attack { get; set; }
        public Int32 Defence { get; set; }
        public IList<ItemContainer> Inventory { get; private set; }
        public String VariableToSetTrueUponDeath { get; set; }
        public String HideIfVariableTrue { get; set; }


        public EnemyDefinition()
        {
            this.Inventory = new List<ItemContainer>();
        }


        public static String GetCsvTitle()
        {
            return "Key,Name,CharacterSetKey,MovementKey,Health,Attack,Defence,AttackKey,AttackSpeed,Inventory,VariableToSetTrueUponDeath,HideIfVariableTrue";
        }


        public String ToCsvString()
        {
            StringBuilder line = new StringBuilder();

            line.Append(Key);
            line.Append(',');
            line.Append(Name);
            line.Append(',');
            
            line.Append(CharacterSetKey);
            line.Append(',');
            line.Append(MovementKey);
            line.Append(',');
            
            line.Append(Health);
            line.Append(',');
            line.Append(Attack);
            line.Append(',');
            line.Append(Defence);
            line.Append(',');

            line.Append(AttackKey);
            line.Append(',');
            line.Append(AttackSpeed);
            line.Append(',');

            line.Append(InventoryToString());
            line.Append(',');

            line.Append(VariableToSetTrueUponDeath);
            line.Append(',');
            line.Append(HideIfVariableTrue);

            return line.ToString();
        }


        private String InventoryToString()
        {
            StringBuilder line = new StringBuilder();

            for(Int32 i = 0; i < Inventory.Count; i++)
            {
                ItemContainer item = Inventory[i];

                line.Append(item.ItemKey);
                line.Append(":");
                if (item.Quantity != null) line.Append(item.Quantity.Value.ToString());
                line.Append(":");
                line.Append(item.ChanceToDrop.ToString());

                if (i != (Inventory.Count-1))
                {
                    line.Append("|");
                }

            }

            return line.ToString();
        }


    }
}
