#pragma once

#ifdef __cplusplus
extern "C"
{
#endif

    enum gem_linetype
    {
        LT_TEXT,
        LT_LINK,
        LT_HEADING,
        LT_LISTITEM,
        LT_QUOTE,
        LT_PRETEXT
    };

    enum gem_resptype
    {
        RT_INPUT = 10,
        RT_SENSITIVE_INPUT = 11,
        RT_SUCCESS = 20,
        RT_TEMPORARY_REDIRECTION = 30,
        RT_PERMANENT_REDIRECTION = 31,
        RT_TEMPORARY_FAILURE = 40,
        RT_SERVER_UNAVAILABLE = 41,
        RT_CGI_ERROR = 42,
        RT_PROXY_ERROR = 43,
        RT_SLOW_DOWN = 44,
        RT_PERMANENT_FAILURE = 50,
        RT_NOT_FOUND = 51,
        RT_GONE = 52,
        RT_PROXY_REFUSED = 53,
        RT_BAD_REQUEST = 54,
        RT_CERTIFICATE_REQUIRED = 60,
        RT_CERTIFICATE_UNAUTHORIZED = 61,
        RT_CERTIFICATE_NOT_VALID = 62,
        RT_INVALID = -1
    };

    struct gem_response
    {
        enum gem_resptype type;
        char *data;
    };

    struct gem_line
    {
        enum gem_linetype type;
        char *text;
        union
        {
            char *url;
            int level;
        };
    };

    struct gem_parse_state
    {
        char *buf;
        int preformatted;
    };

    enum gem_parse_result
    {
        /* Invalid input, parsing failed */
        PARSE_FAIL = -1,
        /* No output line generated (i.e. preformatting toggle) */
        PARSE_NOLINE = 0,
        /* Output line generated */
        PARSE_LINE = 1
    };

    enum gem_parse_result GemParseLine(struct gem_parse_state *, struct gem_line *);
    struct gem_response GemParseResponse(char *response_line);
    const char *gem_typename(enum gem_linetype);

#ifdef __cplusplus
}
#endif