package net.minecraft.world.level.saveddata.maps;

import net.minecraft.network.chat.IChatBaseComponent;

import com.bergerkiller.bukkit.common.wrappers.ChatText;

import com.bergerkiller.generated.net.minecraft.world.level.saveddata.maps.MapIconHandle;
import com.bergerkiller.generated.net.minecraft.world.level.saveddata.maps.MapIconHandle.TypeHandle;

class MapIcon {

    <code>
    public static MapIconHandle createNew(byte type, byte x, byte y, byte direction) {
        return createNew(type, x, y, direction, null);
    }
    </code>

#if version >= 1.13
    public static (MapIconHandle) MapIcon createNew((byte) MapIcon.Type type, byte x, byte y, byte direction, (ChatText) IChatBaseComponent title) {
        return new MapIcon(type, x, y, direction, title);
    }

    public static (MapIconHandle) MapIcon fromCursor(org.bukkit.map.MapCursor cursor) {
        IChatBaseComponent title = null;
        if (cursor.getCaption() != null) {
            title = (IChatBaseComponent) com.bergerkiller.bukkit.common.wrappers.ChatText.fromMessage(cursor.getCaption()).getRawHandle();
        }
  #if version >= 1.18
        return new MapIcon(MapIcon$Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), title);
  #else
        return new MapIcon(MapIcon$Type.a(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), title);
  #endif
    }

    public org.bukkit.map.MapCursor toCursor() {
  #if version >= 1.14.4
        IChatBaseComponent title = instance.getName();
        MapIcon$Type type = instance.getType();
  #else
        IChatBaseComponent title = instance.g();
        MapIcon$Type type = instance.b();
  #endif

  #if version >= 1.18
        byte iconId = type.getIcon();
        byte rotation = instance.getRot();
  #else
        byte iconId = type.a();
        byte rotation = instance.getRotation();
  #endif

        if (title != null) {
            return new org.bukkit.map.MapCursor(
                instance.getX(), instance.getY(), rotation,
                iconId,
                true,
                com.bergerkiller.bukkit.common.wrappers.ChatText.fromComponent(title).getMessage()
            );
        } else {
            return new org.bukkit.map.MapCursor(
                instance.getX(), instance.getY(), rotation,
                iconId,
                true
            );
        }
    }
#elseif version >= 1.11
    public static (MapIconHandle) MapIcon createNew((byte) MapIcon.Type type, byte x, byte y, byte direction, (ChatText) IChatBaseComponent title) {
        return new MapIcon(type, x, y, direction);
    }

    public static (MapIconHandle) MapIcon fromCursor(org.bukkit.map.MapCursor cursor) {
        return new MapIcon(MapIcon$Type.a(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection());
    }

    public org.bukkit.map.MapCursor toCursor() {
        return new org.bukkit.map.MapCursor(
            instance.getX(), instance.getY(), instance.getRotation(),
            instance.getType(),
            true
        );
    }
#else
    public static (MapIconHandle) MapIcon createNew(byte type, byte x, byte y, byte direction, (ChatText) IChatBaseComponent title) {
         return new MapIcon(type, x, y, direction);
    }

    public static (MapIconHandle) MapIcon fromCursor(org.bukkit.map.MapCursor cursor) {
        return new MapIcon(cursor.getRawType(), cursor.getX(), cursor.getY(), cursor.getDirection());
    }

    public org.bukkit.map.MapCursor toCursor() {
        return new org.bukkit.map.MapCursor(
            instance.getX(), instance.getY(), instance.getRotation(),
            instance.getType(),
            true
        );
    }
#endif

#if version >= 1.18
    public byte getTypeId() {
        return instance.getType().getIcon();
    }
#elseif version >= 1.14.4
    public byte getTypeId() {
        return instance.getType().a();
    }
#elseif version >= 1.13
    public byte getTypeId() {
        return instance.b().a();
    }
#else
    public byte getTypeId:getType();
#endif

    public byte getX();

    public byte getY();

#if version >= 1.18
    public byte getDirection:getRot();
#else
    public byte getDirection:getRotation();
#endif

    optional class MapIcon.Type {
#if version >= 1.18
        public static (MapIconHandle.TypeHandle) MapIcon.Type fromId:byIcon(byte id);
#else
        public static (MapIconHandle.TypeHandle) MapIcon.Type fromId:a(byte id);
#endif
    }
}