package org.aohe.variable;

import org.aohe.core.twain.Twain;
import org.aohe.exceptions.TwainException;
import org.aohe.utils.TwainUtils;

public class TwainOneValue extends TwainContainer {

    Object item;

    public TwainOneValue(int cap, byte[] container) {
        super(cap, container);
        item = get32BitObjectAt(container, 2);
    }

    @Override
    public int getType() {
        return Twain.TWON_ONEVALUE;
    }

    @Override
    public byte[] getBytes() {
        byte[] container = new byte[6];
        TwainUtils.setINT16(container, 0, type);
        set32BitObjectAt(container, 2, item);
        return container;
    }

    @Override
    public Object getCurrentValue() throws TwainException {
        return item;
    }

    @Override
    public void setCurrentValue(Object obj) throws TwainException {
        item = obj;
    }

    @Override
    public Object getDefaultValue() throws TwainException {
        return item;
    }

    @Override
    public void setDefaultValue(Object obj) throws TwainException {
        item = obj;
    }

    @Override
    public <T> T[] getItems() {
        Object[] items = new Object[1];
        items[0] = item;
        return (T[]) items;
    }
}
