
#ifndef COMPONENT_H
#define COMPONENT_H

#include <WString.h>
#include <Streaming.h>

#include "../common/constants.h"
#include "../common/macros.h"
#include "../enums.h"
#include "../common/error_codes.h"

#define COMPONENT_DEFAULT 1 << LOOP | 1 << INFO | 1 << SETUP
#define COMPONENT_NO_ID 0


class Component
{
public:
    enum COMPONENT_FLAGS
    {
        NONE = 0,
        DEBUG = 1,
        INFO = 2,
        LOOP = 3,
        DISABLED = 4,
        SETUP = 5,
        MAIN = 6,
        STATE = 7
    };

    Component() : name(NO_NAME), id(0), flags(COMPONENT_FLAGS::NONE) {}

    Component(String _name) : name(_name), id(0), flags(COMPONENT_FLAGS::NONE) {}

    Component(String _name, short _id) : name(_name), id(_id), flags(COMPONENT_FLAGS::NONE) {}

    Component(String _name, short _id, short _flags) : name(_name), id(_id), flags(_flags) {}

    ~Component() {}

    const String name;
    const short id;
    byte flags;

    virtual short debug(Stream *stream) { return E_OK; }
    virtual short info(Stream *stream) { return E_OK; }
    virtual short setup() { return E_OK; }
    virtual short loop() { return E_OK; }

    bool hasFlag(byte flag)
    {
        return TEST(flags, flag);
    }
    void setFlag(byte flag)
    {
        SBI(flags, flag);
    }
    void clearFlag(byte flag)
    {
        CBI(flags, flag);
    }

};

#endif
