using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;

namespace GODS
{
	using MarkData;
	using MarkGUI;

	/// <summary>
	/// Summary description for MarkManager.
	/// </summary>
	public class MarkManager
	{
		private ArrayList categories;

		public MarkManager()
		{
			this.loadCategories();
		}

		public void loadMarkPanel(Panel markPanel, MarkSet markSet)
		{
			MarkGroupView mgView;
			int x = 5;
			int y = 5;
			markPanel.Controls.Clear();
			foreach (MarkGroup group in markSet.MarkGroups)
			{
				mgView = new MarkGroupView(group);
				mgView.Location = new Point(x, y);
				y += mgView.Height + 10;
				markPanel.Controls.Add(mgView);
			}
		}

		public ArrayList Categories
		{
			get 
			{
				return this.categories;
			}
		}

		protected MarkCategory addCategory(string cName)
		{
			MarkCategory cat = this.getCategory(cName);
			if (cat == null)
			{
				cat = new MarkCategory(cName);
				this.categories.Add(cat);
				return cat;
			}
			else
			{
				throw new System.Exception("Dupplicate category: Category with the same name already exists.");
			}
		}

		protected void removeCategory(MarkCategory cat)
		{
			this.categories.Remove(cat);
		}

		public MarkCategory getCategory(string cName)
		{
			foreach (MarkCategory cat in this.categories)
			{
				if (cName.Equals(cat.CategoryName))
				{
					return cat;
				}
			}
			return null;
		}

		private void loadCategories()
		{
			this.categories = new ArrayList();
			
			// Construct dummy data
			// Should use DBWrapper to get mark data
			MarkCategory cat = new MarkCategory("Breast Imaging");
			MarkSet ms = new MarkSet(cat, 1, "Sketch");
			this.loadMarkset(ms);
			cat.addMarkSet(ms);
			
			ms = new MarkSet(cat, 2, "Mammogram");
			this.loadMarkset(ms);
			cat.addMarkSet(ms);
			this.categories.Add(cat);

			cat = new MarkCategory("Brain Imaging");
			ms = new MarkSet(cat, 3, "Middle Brain");
			this.loadMarkset(ms);
			cat.addMarkSet(ms);
			ms = new MarkSet(cat, 4, "Small Brain");
			this.loadMarkset(ms);
			cat.addMarkSet(ms);
			this.categories.Add(cat);
			
			cat = new MarkCategory("Cardiatric Imaging");
			ms = new MarkSet(cat, 5, "Heart 1");
			this.loadMarkset(ms);
			cat.addMarkSet(ms);
			ms = new MarkSet(cat, 6, "Heart 2");
			this.loadMarkset(ms);
			cat.addMarkSet(ms);

			this.categories.Add(cat);
		}

		// Temporary method to create fake data
		private void loadMarkset(MarkSet ms)
		{
			string dir = GODS.GODSMain.ExecDir + @"marks\";
			MarkGroup mg = new MarkGroup(ms, "Breast Lesion");
			Mark m = new Mark(ms, mg, "Lump", dir+"lump.gif", "desc");
			mg.addMark(m);
			m = new Mark(ms, mg, "Hlump", dir+"hlump.gif", "desc");
			mg.addMark(m);
			m = new Mark(ms, mg, "Vlump", dir+"vlump.gif", "desc");
			mg.addMark(m);
			m = new Mark(ms, mg, "Cyst Drained", dir+"cyst.gif", "desc");
			mg.addMark(m);
			m = new Mark(ms, mg, "Thick", dir+"thick.gif", "desc");
			mg.addMark(m);
			m = new Mark(ms, mg, "R Gynecomastia", dir+"gynecR.gif", "desc");
			mg.addMark(m);
			m = new Mark(ms, mg, "L Gynecomastia", dir+"gynecL.gif", "desc");
			mg.addMark(m);
			m = new Mark(ms, mg, "Axillary Fat Pad", dir+"axil.gif", "desc");
			mg.addMark(m);
			m = new Mark(ms, mg, "Mastectomy", dir+"cut.gif", "desc");
			mg.addMark(m);
			ms.addMarkGroup(mg);

			mg = new MarkGroup(ms, "Nipple Lesion");
			m = new Mark(ms, mg, "Inverted", dir+"invertNip.gif", "desc");
			mg.addMark(m);
			m = new Mark(ms, mg, "Echzematoid", dir+"echzemNip.gif", "desc");
			mg.addMark(m);
			ms.addMarkGroup(mg);

			mg = new MarkGroup(ms, "Node");
			m = new Mark(ms, mg, "Node", dir+"node.gif", "desc");
			m.addValue("Negative");
			m.addValue("Positive");
			m.addValue("Shotty");
			m.addValue("Suspicious");
			mg.addMark(m);
			ms.addMarkGroup(mg);

			mg = new MarkGroup(ms, "Nipple Discharge");
			m = new Mark(ms, mg, "Right", null, "desc");
			m.addValue("none");
			m.addValue("bloody, one duct");
			m.addValue("bloody, multiple duct");
			m.addValue("not bloody, one duct");
			m.addValue("not bloody, multiple duct");
			mg.addMark(m);
			m = new Mark(ms, mg, "Left", null, "desc");
			m.addValue("none");
			m.addValue("bloody, one duct");
			m.addValue("bloody, multiple duct");
			m.addValue("not bloody, one duct");
			m.addValue("not bloody, multiple duct");
			mg.addMark(m);
			ms.addMarkGroup(mg);

		}
	}
}