#ifndef DEVICE_ITEM_WIDGET_H
#define DEVICE_ITEM_WIDGET_H

#include "ui_deviceItemWidget.h"
#include <QtGui>
#include "deviceItem.h"
#include "chargeFrame.h"
#include <cassert>
#include "protocol.h"
#include "protocol.h"
#include <sstream>

void setButtonIcon(QPushButton * button, const std::string & filePath, unsigned int iconSize);

class CombinedSlider;
class AllDevicesWidget;

class DeviceBackgroundsHolder {
private:
	unsigned long long minimumEnergyPriority_;
	unsigned long long maximumEnergyPriority_;

	std::vector<QString> activeBackgroundStyles_;
	std::vector<QString> deactiveBackgroundStyles_;
	std::vector<QString> foregroundStyles_;

	QString emptyStyle_;
public:
	DeviceBackgroundsHolder();

	void setLimits(unsigned long long min, unsigned long long max);
	QString & getBackgroundFromPriority(unsigned long long priority, bool isActive);
	QString & getForegroundFromPriority(unsigned long long priority, bool isActive);
};

class DeviceItemWidget : public QWidget {
	Q_OBJECT
private:
	Ui::DeviceItemWidget ui_;
	QWidget * parent_;

	bool isActive_;

	DeviceBackgroundsHolder * backgroundsHolder_;
	unsigned long minimumMaximumEnergy_;
signals:
	void settingsChangedSignal();
public slots:
	void energyPrioritySliderValueChangedSlot(unsigned long long value);
	void maximumEnergySliderValueChangedSlot(unsigned long long value);
	void settingsChangedSlot();
public:
	void setState(const answerDeviceEnergyState & state, const answerDeviceEnergy & fullState);
	requestDeviceEnergyState getState();

	void setDeviceIcon(const std::string & deviceIconPath);
	void setDeviceName(const std::wstring & deviceName);
	DeviceItemWidget(const std::wstring & name, QWidget * parent, DeviceBackgroundsHolder * backgroundsHolder);

	bool getShutDownOnEnergyLack();
	void setShutDownOnEnergyLack(bool value);

	void setEnergyConsumption(unsigned long long value);

	unsigned long long getEnergyRatio();
	void setMinEnergyRatio(unsigned long long value);
	void setMaxEnergyRatio(unsigned long long value);
	void setEnergyRatio(unsigned long long value);

	unsigned long long getEnergyPriority();
	void setEnergyPriority(unsigned long long value);
	void setMinEnergyPriority(unsigned long long value);
	void setMaxEnergyPriority(unsigned long long value);

	double getMaximumEnergy();
	void setMaximumEnergy(double value);
	void setMinMaximumEnergy(double value);
	void setMaxMaximumEnergy(double value);
	void refreshBackgroundColor();
private:
	void recolorFromPriority();

	void activateDevice();
	void deactivateDevice();

	void energyPriorityChanged(unsigned long long value);
	void maximumEnergyChanged(unsigned long long value);
};

#endif