#pragma once

#include "MW4.hpp"

#include <Adept\Receiver.hpp>

namespace MechWarrior4 
{

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// MWTable Entry
	//
	class MWTableEntry:
		public Stuff::Plug
	{
	public:
		MWTableEntry(Stuff::MemoryStream *stream);
		
		static void
			ConstructEntryStream(Stuff::Note *note, Stuff::MemoryStream *stream);

		Adept::ResourceID
			GetEntryResourceID()
				{Check_Object(this); return m_entryResourceID;}
		int
			GetEntryID()
				{Check_Object(this); return m_entryID;}
		Stuff::MString
			GetEntryName()
				{Check_Object(this); return m_entryName;}
		Stuff::MString
			GetData()
				{Check_Object(this); return m_data;}

	private:
		Adept::ResourceID
			m_entryResourceID;
		int
			m_entryID;
		Stuff::MString
			m_entryName;
		Stuff::MString
			m_data;
	};


	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// MWTable
	//
	class MWTable:
		public Stuff::Plug
	{
	public:
		MWTable(Stuff::MemoryStream *stream);

		static void
			ConstructTableStream(Stuff::NotationFile *note_file, Stuff::MemoryStream *stream);

		~MWTable();

		MWTableEntry*
			FindEntry(Stuff::MString entry_name);
		MWTableEntry*
			FindEntry(int entry_id)
				{Check_Object(this); STOP(("Not Implemented")); return NULL;}
		MWTableEntry*
			FindEntryFromDataString(Stuff::MString data);
		int
			FindIndexFromDataString(Stuff::MString data);
		MWTableEntry*
			GetNthItem(int num)
				{Check_Object(this); return m_table.GetNth(num);}

		typedef Stuff::SortedChainIteratorOf<MWTableEntry *, Stuff::MString> TableIterator;

		TableIterator*
			MakeTableIterator()
				{Check_Object(this); return new TableIterator(&m_table);}
		int
			GetTableSize()
				{Check_Object(this); return m_table.GetSize();}

	private:
		Stuff::SortedChainOf<MWTableEntry *, Stuff::MString>
			m_table;
	};
}
