package common.tileentity;

import common.tags.TagObject;

public abstract class TileEntityLockable extends TileEntity implements IInteractionObject, ILockableContainer
{
    private Passcode code = Passcode.EMPTY_CODE;

    public void readTags(TagObject compound)
    {
        super.readTags(compound);
        this.code = Passcode.fromNBT(compound);
    }

    public void writeTags(TagObject compound)
    {
        super.writeTags(compound);

        if (this.code != null)
        {
            this.code.toNBT(compound);
        }
    }

    public boolean isLocked()
    {
        return this.code != null && !this.code.empty();
    }

    public Passcode getLockCode()
    {
        return this.code;
    }

    public void setLockCode(Passcode code)
    {
        this.code = code;
    }
    
    public abstract String getName();
    public abstract boolean hasCustomName();

    /**
     * Get the formatted ChatComponent that will be used for the sender's username in chat
     */
    public String getCommandName()
    {
        return this.getName(); // (TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName()));
    }
}
