package vermilion;

import java.util.ArrayList;

/**
 * A parameter meant to represent a continuous slider. This is stored as
 * a value between 0000 and 9999.
 */
public class ParameterCommand extends ParameterBase
{
    public int command;
    public int argument;

    /**
     * This constructor creates a parameter.
     * @param name A name for this parameter.
     * @param isTrack Indicates whether the parameter is global.
     */
    public ParameterCommand(String name, boolean isTrack)
    {
        super(name, PARAMETER_TYPE_COMMAND, isTrack);
        command = 0;
        argument = 0;
    }

    /**
     * This constructor creates a command.
     */
    public ParameterCommand(int cmdVal, int argVal)
    {
        super(PARAMETER_TYPE_COMMAND);
        command = cmdVal;
        argument = argVal;
    }

    /**
     * The serialisation type for this object is 'CMD'.
     */
    @Override
    public String getType() { return "CMD"; }

    /**
     * The current serialisation version for this object is 1.
     */
    @Override
    public int getVersion() { return 1; }

    @Override
    public String saveImpl()
    {
        ArrayList<String> strs = new ArrayList<String>();

        strs.add(String.valueOf(command));
        strs.add(String.valueOf(argument));

        return listToString(strs);
    }

    @Override
    public UsefulFileObject loadImpl(String str, int version)
    {
        if (version == 1)
        {
            ParameterCommand node = new ParameterCommand(0, 0);

            ArrayList<String> data = stringToList(str);

            if (data.size() >= 2)
            {
                node.command = Integer.parseInt(data.get(0));
                node.argument = Integer.parseInt(data.get(1));
            }

            return node;
        }

        return null;
    }

    @Override
    public void copyValue(ParameterBase source)
    {
        command = ((ParameterCommand) source).command;
        argument = ((ParameterCommand) source).argument;
    }

    @Override
    public String printValue()
    {
        // TODO: Fix up so it is padded like in JTrackerColumnCommand
        return (char) ('A' + command) + String.valueOf(argument);
    }
}
