#ifndef TEXTURE_OPERATION_PARSER_H
#define TEXTURE_OPERATION_PARSER_H

#include "texture\TextureSupport.h"
#include "mathParser\mathStringParser.h"
#include "mathParser\mathParser.h"
#include "texture\TextureComposer.h"

enum TreeTextureNodeType
{
	TEXTURE_NODE,
	NUMBER_NODE
};


class TreeTextureNode
{
public:
	bool isTextureNode;
	Texture<unsigned char> texture;
	float value;

	TreeTextureNode(void)
	{
		this->isTextureNode = false;
		this->value = 1;
	}

	TreeTextureNode( const string &textureName ) 
	{ 
		bool ok;
		ok=TextureManager::readTexture( textureName, this->texture);
		assert(ok && "Texture reading failed." );
		this->isTextureNode = true;
	}
	TreeTextureNode( const float value ) 
	{ 
		this->isTextureNode = false;
		this->value= value;
	}

	TreeTextureNode operator+( const TreeTextureNode& node)
	{
		TreeTextureNode res;

		if ( this->isTextureNode && node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->texture.internalData + node.texture.internalData;
		}
		if ( !this->isTextureNode && node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = node.texture.internalData + this->value;
		}
		if ( this->isTextureNode && !node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->texture.internalData + node.value;
		}
		if ( !this->isTextureNode && !node.isTextureNode )
		{
			res.isTextureNode = false;
			res.value = this->value + node.value;
		}

		return res;
	}

	TreeTextureNode operator-( const TreeTextureNode& node)
	{
		TreeTextureNode res;

		if ( this->isTextureNode && node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->texture.internalData - node.texture.internalData;
		}
		if ( !this->isTextureNode && node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData =  this->value - node.texture.internalData;
		}
		if ( this->isTextureNode && !node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->texture.internalData - node.value;
		}
		if ( !this->isTextureNode && !node.isTextureNode )
		{
			res.isTextureNode = false;
			res.value = this->value - node.value;
		}

		return res;
	}
	TreeTextureNode operator/( const TreeTextureNode& node)
	{
		TreeTextureNode res;

		if ( this->isTextureNode && node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->texture.internalData / node.texture.internalData;
		}
		if ( !this->isTextureNode && node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->value / node.texture.internalData;
		}
		if ( this->isTextureNode && !node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->texture.internalData / node.value;
		}
		if ( !this->isTextureNode && !node.isTextureNode )
		{
			res.isTextureNode = false;
			res.value = this->value / node.value;
		}

		return res;
	}
	TreeTextureNode operator*( const TreeTextureNode& node)
	{
		TreeTextureNode res;

		if ( this->isTextureNode && node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->texture.internalData * node.texture.internalData;
		}
		if ( !this->isTextureNode && node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->value * node.texture.internalData;
		}
		if ( this->isTextureNode && !node.isTextureNode )
		{
			res.isTextureNode = true;
			res.texture.internalData = this->texture.internalData * node.value;
		}
		if ( !this->isTextureNode && !node.isTextureNode )
		{
			res.isTextureNode = false;
			res.value = this->value * node.value;
		}

		return res;
	}
};

#endif