#include "clientState.h"

ShipSectionState::ShipSectionState() {
	currentShip.id = 0;
	currentShip.classId = 0;
	state = SHIP_NONE;
}

bool ShipSectionState::hasCurrentShip() {
	return currentShip.id != 0;
}

id_t ShipSectionState::getCurrentShipId() {
	return currentShip.id;
}

SimpleItem ShipSectionState::getCurrentShip() {
	return currentShip;
}

void ShipSectionState::setCurrentShip(const SimpleItem & ship) {
	this->currentShip = ship;
}

bool ShipSectionState::isInState(EShipSectionState state) {
	return this->state == state;
}

void ShipSectionState::changeState(EShipSectionState state) {
	this->state = state;
}

BaseSectionState::BaseSectionState() {
	currentBase.id = 0;
	currentBase.classId = 0;
	state = BASE_NONE;
}

bool BaseSectionState::hasCurrentBase() {
	return currentBase.id != 0;
}

id_t BaseSectionState::getCurrentBaseId() {
	return currentBase.id;
}

SimpleItem BaseSectionState::getCurrentBase() {
	return currentBase;
}

void BaseSectionState::setCurrentBase(const SimpleItem & base) {
	this->currentBase = base;
}

bool BaseSectionState::isInState(EBaseSectionState state) {
	return this->state == state;
}

void BaseSectionState::changeState(EBaseSectionState state) {
	this->state = state;
}

ClientState::ClientState() {
	this->mainState = MAIN_NONE;
	this->shipSectionState.state = SHIP_NONE;
	this->baseSectionState.state = BASE_NONE;

	invalidFortress.id = 0;
}

void ClientState::changeMainState(EMainState mainState) {
	this->mainState = mainState;
}

bool ClientState::isInState(EMainState mainState) {
	return this->mainState == mainState;
}

bool ClientState::hasCurrentFortress() {
	if (mainState == SHIP_SECTION) {
		return shipSectionState.hasCurrentShip();
	}
	else if (mainState == BASE_SECTION) {
		return baseSectionState.hasCurrentBase();
	}
	else {
		return false;
	}
}

const SimpleItem & ClientState::getCurrentFortress() {
	if (mainState == SHIP_SECTION) {
		return shipSectionState.currentShip;
	}
	else if (mainState == BASE_SECTION) {
		return baseSectionState.currentBase;
	}
	else {
		return invalidFortress;
	}
}

bool ClientState::isInState(EMainState mainState, EShipSectionState shipState) {
	return this->mainState == mainState && this->shipSectionState.state == shipState;
}

bool ClientState::isInState(EMainState mainState, EBaseSectionState baseState) {
	return this->mainState == mainState && this->baseSectionState.state == baseState;
}