#ifndef TRADE_ITEM_H
#define TRADE_ITEM_H

#include "softProj\DetailsWidget\SimpleItem.h"
#include "softProj\clientServer\structs.h"
#include "softProj\settings.h"

enum ETradeItemType {
	BASIC_TRADE_ITEM,
	STACKABLE_TRADE_ITEM,
	RESOURCE_TRADE_ITEM,
};

class TradeItem {
public:
	QString name;
	ETradeItemType type;
	warehouse_item_status state_;
private:
public:
	TradeItem(const warehouse_item_status & itemData) {
		this->type = itemData.isStackable ? STACKABLE_TRADE_ITEM : BASIC_TRADE_ITEM;
		this->name = Settings::instance().getGameNameQString(itemData.patternName);
		state_ = itemData;
	}

	TradeItem(const TradeItem & that) {
		this->name = that.name;
		this->type = that.type;
		this->state_ = that.state_;
	}

	unsigned long getCount() {
		if (state_.isStackable) {
			return state_.working + state_.damaged;
		}
		else {
			return 1;
		}
	}

	warehouse_item_status & getWarehouseItem() {
		return state_;
	};
};

class FortressItemRow {
private:
	SimpleItem item_;
	EFortressType fortressType_;
	bool isOwned_;
public:
    QString getNameQString() const {
		return QString::fromUtf8(item_.name.c_str());
    }

    QString getNameAndIDQString() const {
		return QString::fromUtf8(item_.name.c_str()) + " (" + QString::number(item_.id) + ")";
    }

    std::string getName() const {
		return item_.name;
    }

    EFortressType getFortressType() const {
		return fortressType_;
    }

	id_t getId() {
		return item_.id;
	}

	QString getRealmNameQString() const {
		return QString::fromUtf8(item_.realmName.c_str());
	}

	std::string getRealmName() const {
		return item_.realmName;
	}

    FortressItemRow(const SimpleItem & item, EFortressType fortressType, bool isOwned) {
        this->item_ = item;
		this->fortressType_ = fortressType;
		this->isOwned_ = isOwned;
    } 

	bool isShip() {
		return fortressType_ == FORTRESS_TYPE_SHIP;
	}

	bool isOwned() {
		return isOwned_;
	}

	bool isShell() {
		return item_.isShell;
	}
};

#endif
