package com.example.Models.Statements;

import com.example.Exceptions.BaseException;
import com.example.Models.Expressions.IExpression;
import com.example.Models.Program.IDictionary;
import com.example.Models.Program.IQueue;
import com.example.Models.Program.ProgramState;
import com.example.Models.Types.IType;
import com.example.Models.Values.IValue;

public class PrintStatement implements IStatement {
    //region Fields
    private IExpression expression;
    //endregion
    
    //region Exposed Methods
    public PrintStatement(IExpression expression){
        this.expression = expression;
    }
    public String toString(){
        return "print(" + expression.toString() + ")";
    }

    public IStatement copy(){
        return new PrintStatement(expression.copy());
    }

    public ProgramState execute(ProgramState state) throws BaseException{
        IQueue<IValue> output = state.getOutput();
        output.enqueue(expression.evaluate(state.getSymbolTable(), state.getHeap()  ));
        return null;
    }

    public IDictionary<String, IType> typeCheck(IDictionary<String, IType> typeTable) throws BaseException{
        expression.typeCheck(typeTable);
        return typeTable;
    }
    //endregion    
}
