#pragma once

#include "common.h"
#include "syringe.h"
#include "syringefilled.h"

class Cli
{
private:

    SyringeFilled& syringe_filled;

    String _currentInput;
    String _temp;
    const char* _msgHeader = msgHeader; //XXX fixmeconstructorparam
    int _currentWordIndex;
    int _currentWordEndIndex;

    void resetNextWord ();
    const char* findNextWord ();
    void copyNextToTemp ();
    bool kw (const __FlashStringHelper* keyWord, const char* input);
    bool kw (const __FlashStringHelper* keyWord);
    void syntax (const __FlashStringHelper* cmd);
    void syntax (const char* cmd = nullptr);
    void answer (bool ok, const String& error_message = emptyString) const;
    void check_emergency ();

public:

    Cli (SyringeFilled& syringe_filled, int bufferLen = 32): syringe_filled(syringe_filled)
    {
        _currentInput.reserve(bufferLen);
        _temp.reserve(bufferLen);
        resetNextWord();
    }

    void loop (Stream& input);
};