#ifndef _CLI_RESULT_PRINT_STATEMENT_H_
#define _CLI_RESULT_PRINT_STATEMENT_H_

#include <ast/Statement.h>
#include <global/GlobalData.h>
#include <registry/Registry.h>

namespace cli {

class ResultPrintStatement final : public Statement {
public:
	ResultPrintStatement ( ) = default;

	std::shared_ptr < abstraction::Value > translateAndEval ( const std::shared_ptr < abstraction::Value > & prev, Environment & ) const override {
		std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getValuePrinterAbstraction ( prev->getType ( ) );

		if ( res->numberOfParams ( ) == 0 )
			return std::make_shared < abstraction::Void > ( nullptr );

		res->attachInput ( prev, 0, false );
		res->attachInput ( std::make_shared < abstraction::ValueHolder < std::ostream & > > ( nullptr, common::Streams::out ), 1, false );
		std::shared_ptr < abstraction::Value > result = res->eval ( );
		if ( ! result )
			throw std::invalid_argument ( "Eval of result print statement failed." );
		return result;
	}

};

} /* namespace cli */

#endif /* _CLI_RESULT_PRINT_STATEMENT_H_ */
