package org.diorite.material.items.block.door;

import java.util.Map;

import org.diorite.material.WoodTypeMat;
import org.diorite.utils.collections.maps.CaseInsensitiveMap;

import gnu.trove.map.TShortObjectMap;
import gnu.trove.map.hash.TShortObjectHashMap;

@SuppressWarnings("MagicNumber")
public class AcaciaDoorItemMat extends WoodenDoorItemMat
{
    /**
     * Sub-ids used by diorite/minecraft by default
     */
    public static final int USED_DATA_VALUES = 1;

    public static final AcaciaDoorItemMat ACACIA_DOOR_ITEM = new AcaciaDoorItemMat();

    private static final Map<String, AcaciaDoorItemMat>     byName = new CaseInsensitiveMap<>(USED_DATA_VALUES, SMALL_LOAD_FACTOR);
    private static final TShortObjectMap<AcaciaDoorItemMat> byID   = new TShortObjectHashMap<>(USED_DATA_VALUES, SMALL_LOAD_FACTOR, Short.MIN_VALUE);

    protected AcaciaDoorItemMat()
    {
        super("ACACIA_DOOR_ITEM", 430, "minecraft:acacia_door", "ACACIA_DOOR_ITEM", (short) 0x00, WoodTypeMat.ACACIA);
    }

    protected AcaciaDoorItemMat(final String enumName, final int id, final String minecraftId, final String typeName, final short type, final WoodTypeMat woodType)
    {
        super(enumName, id, minecraftId, typeName, type, woodType);
    }

    protected AcaciaDoorItemMat(final String enumName, final int id, final String minecraftId, final int maxStack, final String typeName, final short type, final WoodTypeMat woodType)
    {
        super(enumName, id, minecraftId, maxStack, typeName, type, woodType);
    }

    @Override
    public AcaciaDoorItemMat getType(final int type)
    {
        return getByID(type);
    }

    @Override
    public AcaciaDoorItemMat getType(final String type)
    {
        return getByEnumName(type);
    }

    /**
     * Returns one of AcaciaDoorItem sub-type based on sub-id, may return null
     *
     * @param id sub-type id
     *
     * @return sub-type of AcaciaDoorItem or null
     */
    public static AcaciaDoorItemMat getByID(final int id)
    {
        return byID.get((short) id);
    }

    /**
     * Returns one of AcaciaDoorItem sub-type based on name (selected by diorite team), may return null
     * If block contains only one type, sub-name of it will be this same as name of material.
     *
     * @param name name of sub-type
     *
     * @return sub-type of AcaciaDoorItem or null
     */
    public static AcaciaDoorItemMat getByEnumName(final String name)
    {
        return byName.get(name);
    }

    /**
     * Register new sub-type, may replace existing sub-types.
     * Should be used only if you know what are you doing, it will not create fully usable material.
     *
     * @param element sub-type to register
     */
    public static void register(final AcaciaDoorItemMat element)
    {
        byID.put(element.getType(), element);
        byName.put(element.getTypeName(), element);
    }

    @Override
    public AcaciaDoorItemMat[] types()
    {
        return AcaciaDoorItemMat.acaciaDoorItemTypes();
    }

    /**
     * @return array that contains all sub-types of this block.
     */
    public static AcaciaDoorItemMat[] acaciaDoorItemTypes()
    {
        return byID.values(new AcaciaDoorItemMat[byID.size()]);
    }

    static
    {
        AcaciaDoorItemMat.register(ACACIA_DOOR_ITEM);
    }
}

