#include "arc/std/chemical.h"
#include "arc/std/parser/helpers.h"
#include "arc/std/bool.h"
#include "arc/std/hashtable.h"
#include "arc/std/parser.h"
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

struct ARC_Chemical {
    ARC_Parser *parser;

    ARC_Hashtable *groups;
};

void ARC_Chemical_InitLexerRulesFn(ARC_Lexer *lexer){
}

uint32_t ARC_Chemical_GetStringIdFn(ARC_String *string){
    if(ARC_String_EqualsCStringWithStrlen(string, "LAMBDA")){
        return ARC_PARSER_TAG_LAMBDA;
    }

    return ~(uint32_t)0;
}

void ARC_ChemicalData_CreateFn(void **data, ARC_ParserTagToken *parsedData, void *userData){
    *data = NULL;
    if(data == NULL || userData == NULL){
        //TODO: error here?
        *data = NULL;
        return;
    }
}

void ARC_Chemical_Create(ARC_Chemical **chemical){
    *chemical = (ARC_Chemical *)malloc(sizeof(ARC_Chemical));

    /* ~ define the language as a string ~ */
    char *languageCString =
        "<language>     -> <group> <language> | <variableLine> <language> | <whitespace> <language>\n"

        "<group>        -> <groupName> <whitespace> <variable> <whitespace> LEFT_CURLY_BRACE <whitespace> <variableLine> <whitespace> RIGHT_CURLY_BRACE\n"

        "<variableLine> -> <type> <whitespace> <variable> <whitespace> EQUALS <whitespace> value <whitespace> SEMICOLON <whitespace>\n"

        "<groupName>    -> <variable>\n"
        "<type>         -> <variable>\n"
        "<value>        -> <variable> | <number> | <nestedValue>\n"
        "<nestedValue>  -> OPEN_CURLY_BRACE <whitespace> <valueArgs> <whitespace> CLOSE_CURLY_BRACE\n"
        "<valueArgs>    -> <value> | <value> COMMA <valueArgs>\n"

        "<variable>     -> ALPHA_UPPER_CHAR <variableName> | ALPHA_LOWER_CHAR <variableName> | UNDERSCORE <variableName>\n"
        "<variableName> -> <charOrNum> <variableName> | LAMBDA\n"
        "<charOrNum>    -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUM\n"

        "<number>       -> NUMBER <number> | NUMBER LAMBDA\n"

        "<whitespace>   -> SPACE <whitespace> | TAB <whitespace> | NEWLINE <whitespace> | LAMBDA\n";

    /* ~ define the language as a string ~ */
    ARC_String *languageString;
    ARC_String_CreateWithStrlen(&languageString, languageCString);

    /* ~ init the userdata? ~ */

    /* ~ create the language ~ */
    //ARC_ParserData_CreateFn  createCharFn  = ARC_ChemicalData_CreateFn;
    //ARC_ParserData_DestroyFn destroyCharFn = ARC_ChemicalData_DestroyFn;
    //ARC_Parser_CreateFromString(parser, languageString, ARC_ParserCSV_InitLexerRulesFn, ARC_ParserCSV_GetStringIdFn, &createCharFn, &destroyCharFn, userdata);

    //cleanup
    ARC_String_Destroy(languageString);
}

void ARC_Chemical_Destroy(ARC_Chemical *chemical){
}

void ARC_Chemical_RegisterType(ARC_Chemical *chemical, ARC_String *typeName, ARC_ChemicalData_CopyToTypeFn *copyToTypeFn, ARC_ParserCSV_DestroyTypeFn destroyTypeFn){
}

void ARC_Chemical_SetGroup(ARC_Chemical *chemical, ARC_String *groupName){
}

void *ARC_Chemical_Get(ARC_Chemical *chemical, ARC_String *element){
    return NULL;
}

void ARC_Chemical_LoadFromString(ARC_String *path){
}

void ARC_Chemical_LoadFromFile(ARC_String *path){
}

void ARC_Chemical_UnloadFromString(ARC_String *data){
}

void ARC_Chemical_UnloadFromFile(ARC_String *data){
}
