
#ifndef PORYGONLANG_SIMPLEKEYITERATOR_HPP
#define PORYGONLANG_SIMPLEKEYITERATOR_HPP

#include "Iterator.hpp"
#include "../EvalValues/TableEvalValue.hpp"
#include "../EvalValues/StringEvalValue.hpp"

namespace Porygon::Evaluation{
    class TableKeyIterator : public Iterator{
        _Rb_tree_const_iterator<pair<const Utilities::HashedString, EvalValuePointer>>  _iterator;
        _Rb_tree_const_iterator<pair<const Utilities::HashedString, EvalValuePointer>>  _end;
        bool _hasStarted = false;
    public:
        explicit TableKeyIterator(const TableEvalValue* table)
                : _iterator(table->GetTableIterator()), _end(table->GetTableIteratorEnd()){}

        inline const EvalValue* GetCurrent() final{
            return new StringEvalValue(*_iterator->first.GetString());
        }

        bool MoveNext() final{
            if (_hasStarted){
                std::advance(_iterator, 1);
            } else{
                _hasStarted = true;
            }
            return _iterator != _end;
        }

        inline void Reset() final{
            throw EvaluationException("Can't reset table key iterator");
        }
    };
}



#endif //PORYGONLANG_SIMPLEKEYITERATOR_HPP
