import net.minestom.server.entity.Entity;
import net.minestom.server.tag.Tag;
import net.minestom.server.tag.TagReadable;
import net.minestom.server.tag.TagWritable;

public class EntityTagUtils {
    
    // String tag
    private static final Tag<String> STRING_TAG = Tag.String("custom_string");
    
    // Integer tag
    private static final Tag<Integer> INT_TAG = Tag.Integer("custom_int");
    
    // Double tag
    private static final Tag<Double> DOUBLE_TAG = Tag.Double("custom_double");
    
    // Boolean tag
    private static final Tag<Boolean> BOOLEAN_TAG = Tag.Boolean("custom_boolean");
    
    // Set string tag on entity
    public static void setStringData(Entity entity, String value) {
        if (entity instanceof TagWritable writable) {
            writable.setTag(STRING_TAG, value);
        }
    }
    
    // Get string tag from entity
    public static String getStringData(Entity entity) {
        if (entity instanceof TagReadable readable) {
            return readable.getTag(STRING_TAG);
        }
        return null;
    }
    
    // Set integer tag
    public static void setIntData(Entity entity, Integer value) {
        if (entity instanceof TagWritable writable) {
            writable.setTag(INT_TAG, value);
        }
    }
    
    // Get integer tag
    public static Integer getIntData(Entity entity) {
        if (entity instanceof TagReadable readable) {
            return readable.getTag(INT_TAG);
        }
        return null;
    }
    
    // Set double tag
    public static void setDoubleData(Entity entity, Double value) {
        if (entity instanceof TagWritable writable) {
            writable.setTag(DOUBLE_TAG, value);
        }
    }
    
    // Get double tag
    public static Double getDoubleData(Entity entity) {
        if (entity instanceof TagReadable readable) {
            return readable.getTag(DOUBLE_TAG);
        }
        return null;
    }
    
    // Set boolean tag
    public static void setBooleanData(Entity entity, Boolean value) {
        if (entity instanceof TagWritable writable) {
            writable.setTag(BOOLEAN_TAG, value);
        }
    }
    
    // Get boolean tag
    public static Boolean getBooleanData(Entity entity) {
        if (entity instanceof TagReadable readable) {
            return readable.getTag(BOOLEAN_TAG);
        }
        return null;
    }
    
    // Set multiple tags at once
    public static void setEntityData(Entity entity, String stringValue, Integer intValue, Double doubleValue) {
        if (entity instanceof TagWritable writable) {
            writable.setTag(STRING_TAG, stringValue);
            writable.setTag(INT_TAG, intValue);
            writable.setTag(DOUBLE_TAG, doubleValue);
        }
    }
    
    // Check if entity has tag
    public static boolean hasTag(Entity entity, Tag<?> tag) {
        if (entity instanceof TagReadable readable) {
            return readable.hasTag(tag);
        }
        return false;
    }
    
    // Remove tag
    public static void removeTag(Entity entity, Tag<?> tag) {
        if (entity instanceof TagWritable writable) {
            writable.removeTag(tag);
        }
    }
}