const classDataKey = "tfc_classes:class";

global.tfc_classes_util = {};

global.tfc_classes_util.checkIncludes = (haystack, needle) =>
{
    if(haystack.includes(needle))
    {
        return true;
    }
    for(const element of haystack)
    {
        if(element.startsWith("#"))
        {
            const tag = element.substring(1);
            let item = Item.of(needle);
            if(item && item.hasTag(tag))
            {
                return true;
            }
            let block = Block.id(needle);
            if(block && block.blockState.hasTag(tag))
            {
                return true;
            }
        }
        else if(needle.match(element))
        {
            return true;
        }
    }
    return false;
};

global.tfc_classes_util.setClassOfPlayer = (player, classId) =>
{
    const persistentData = player.persistentData;
    persistentData.putString(classDataKey, classId);
}

global.tfc_classes_util.getClassOfPlayer = (player) =>
{
    const persistentData = player.persistentData;
    const classId = persistentData.getString(classDataKey);
    if(classId)
    {
        let playerClass = global.tfc_classes[classId];
        if(playerClass)
        {
            return playerClass;
        }
    }
    return null;
}