#ifndef IRC_CMD_HPP_
#define IRC_CMD_HPP_
#include "irc_msg.hpp"


#define IRC_MAX_CMD_PARAMS 5 // upper arg limit of commands (we do support)

typedef enum command_type_e {
    CMD_UNKNOWN=0,
    CMD_PASS, CMD_CAP, CMD_NICK, CMD_USER, CMD_OPER, CMD_MOTD, CMD_JOIN, CMD_WHO, CMD_LIST, CMD_AWAY, CMD_MODE, CMD_TOPIC, CMD_PING, CMD_PONG, CMD_PRIVMSG, CMD_PART, CMD_QUIT, CMD_NICKSERV
} command_type_t;


class Command {
    public:
        typedef struct {
            command_type_t t;
            const char* s;
            unsigned nparams_min;
            unsigned nparams_max;
            bool from_privmsg;
        } command_info_t;

    private:
        Command(const command_info_t*);
        static const command_info_t* parse_cmd(char*&);
        bool parse_params(char*);
        msg_t* cleanup; ///< shall be freed upon destruction

    public:
        static Command* parse(msg_t*); ///< creates instance from parsed string. NULL upon severe parsing error, UNKNOWN upon other errors. frees argument in any case.
        ~Command();

        const command_info_t* const type;
        char* params[IRC_MAX_CMD_PARAMS]; ///< null-terminated, non-empty command args
        unsigned nparams; ///< number of filled args in #params

        static bool is_command(const char*); ///< returns whether the given nick can be used as command
};


#endif