#ifndef ANDROIDS_WIDGET_H
#define ANDROIDS_WIDGET_H

#include <QtGui>
#include "ui_androidsWidget.h"
#include "softProj\clientServer\structs.h"
#include "androidsSectionWidget.h"
#include "softProj\Main\INotifyUpdate.h"
#include "softProj\DevicesWidget\deviceItemWidget.h"

/** Possible section repairment types */
enum ESectionType {
	ANDROIDS_SECTION_STRUCTURAL_INTEGRITY,
	ANDROIDS_SECTION_ENERGETIC_ACCUMULATOR,
	ANDROIDS_SECTION_SHIELDS,
	ANDROIDS_SECTION_WEAPONS,
	ANDROIDS_SECTION_TRANSPORT,
	ANDROIDS_SECTION_QUARRYING,
	ANDROIDS_SECTION_PROBES,
	ANDROIDS_SECTION_SENSORS,
	ANDROIDS_SECTION_MASKING,
	ANDROIDS_SECTION_ANDROIDS,
	ANDROIDS_SECTION_WAREHOUSES,
	ANDROIDS_SECTION_EQUIPMENT,
	ANDROIDS_SECTION_MAINFRAME,
	ANDROIDS_SECTION_HANGARS,
	ANDROIDS_SECTION_FACTORIES,
	ANDROIDS_SECTION_IMPULS_DRIVE,
	ANDROIDS_SECTION_SUBSPACE_DRIVE,
};

/// Widget for androids section in fortress 
/** Widget for androids section in fortress. It is composed from sliders for setting amount of working androids
and amount of not working androids and slider for divison of androids between repairment and construction. Then it 
contains instances of AndroidSectionWidget that represents repairment settings for concrete sections of the fortress */
class AndroidsWidget : public NotifyWidget {
	Q_OBJECT
signals:
	/** Signals that widget should be synchronized from server and all changes should be dropped */
	void androidsShipResetSignal();

	/** Signals that widget should be synchronized from server and all changes should be dropped */
	void androidsBaseResetSignal();

	/** Signals that widget settings state should be sent to server
	@param state State of settings in the widget
	*/
	void androidsShipSubmitSignal(ship_androids_request_status & state);

	/** Signals that widget settings state should be sent to server
	@param state State of settings in the widget
	*/
	void androidsBaseSubmitSignal(base_androids_request_status & state);

	/** Signals that user wants to unmount items
	@param patternName Name of pattern for device to unmount
	@param maxWorking Maximum number of working items to unmount
	@param maxDamaged Maximum number of damaged items to unmount
	*/
	void unmountSignal(const std::string & patternName, unsigned long long maxWorking, unsigned long long maxDamaged);

	/** Signals that widget wants to show dialog */
	void showDialogSignal();

	/** Signals that widget wants to hide dialog */
	void hideDialogSignal();
private slots:
	/** Slot for clicking submit button
	@param checked If checked
	*/
	void submitSlot(bool checked);

	/** Slot for clicking cancel button
	@param checked If checked
	*/
	void cancelSlot(bool checked);

	/** Slot for changing value of slider representing working androids count.
	It is usefull for adjusting androids asignment slider, where we need to set
	maximum repairing plus cosntructing androids according to new value of androids count.
	@param value New value of count slider
	*/
	void androidsAbleSliderChangedSlot(unsigned long long value);

	/** Slot informing that user changed settings in a widget */
	void settingsChangedSlot();

	/** Slot informing that user clicked button for unmounting */
	void unmountButtonClickedSlot(bool checked);
public:
	/** Creates new instance of AndroidsWidget
	@param parent Parent widget
	*/
	AndroidsWidget(QWidget * parent);

	/** Sets state of the widget from given state holder and assumes widget displays ship information
	@param state State holder that holds information about section settings
	*/
	void setState(ship_androids_status & state);

	/** Sets state of the widget from given state holder and assumes widget displays base information
	@param state State holder that holds information about section settings
	*/
	void setState(base_androids_status & state);

	/** Inits AndroidsSectionWidget.
	It sets to widget a section type, section name and an icon. It also inserts widget to a map with all AndroidsSectionWidgets.
	@param widget Widget to be initialized
	@param sectionType Type of section that given widget should represent
	@param name Name of the section that given widget should represent
	@param iconPath Path to a file with an icon
	*/
	void initDevice(AndroidsSectionWidget * widget, ESectionType sectionType, const std::wstring & name, const std::string & iconPath);

	void notifyUpdate() {}

	~AndroidsWidget();
private:
	enum EAndroidsState {
		ANDROIDS_STATE_SHIP, ANDROIDS_STATE_BASE, ANDROIDS_STATE_NONE,
	};

	Ui::AndroidsWidget ui_;

	EAndroidsState state_;

	std::map<ESectionType, AndroidsSectionWidget * > devices_;
	typedef std::map<ESectionType, AndroidsSectionWidget *>::iterator DevicesIterator;	

	bool isLockedForUpdate_;
	void lockForUpdate(bool lock);

	DeviceBackgroundsHolder * backgroundsHolder_;

	void setCommonAndroidsState(androids_status & state);
	void getCommonAndroidsState(androids_request_status & state);

	base_androids_status baseState_;
	ship_androids_status shipState_;
};

#endif