package ex1;

import java.util.ArrayList;

/**
 *
 * This contains the basic config information for an operations action.
 *
 */
public class OpAction {

    /**
     * name of the action
     */
    public String name;

    /**
     * Ascii code O,G,P
     */
    public char code;

    /**
     * ID of the action, from the <identity> block
     */
    public int id;

    /**
     * code from the <group> block
     */
    public char[] groupCode;

    /**
     * ID from the <group> block
     */
    public int[] groupId;

    /**
     *
     */
    public int groups = 0;

    /**
     *
     */
    public ArrayList<ParamDef> childParms;

    /**
     *
     * @param theName
     * @param theCode
     * @param theId
     */
    public OpAction(String theName, char theCode, int theId) {
        super();
        name = (theName);
        code = theCode;
        id = theId;
        groupCode = new char[10];
        groupId = new int[10];

        for (int i = 0; i < 10; i++) {
            groupCode[i] = '?';
            groupId[i] = -1;
        }

        groups = 0;
    }

    /**
     *
     * @param p
     */
    public void addParmList(ArrayList<ParamDef> p) {
        childParms = p;
    }

    /**
     *
     * @return
     */
    public String getFullName() {
        String p = (String.valueOf(code) + String.valueOf(id) + " - " + name);
        return p;
    }

    /**
     *
     * @param col
     * @return
     */
    public ParamDef getColumn(int col) {
        if (col < childParms.size()) {
            return childParms.get(col);
        } else {
            return null;
        }
    }

    /**
     * Get number of parameters for this process.
     * @return 
     */
    public int getNumChildParms() {
        return childParms.size();
    }

    /**
     * This is the integer portion of P21, O2, etc.
     * @param index
     * @return 
     */
    public int getGroupId(int index) {

        return groupId[index];
    }

    /**
     * This is the character portion of P21, O2, etc
     * @param index
     * @return 
     */
    public char getGroupCode(int index) {
        return groupCode[index];
    }

    /**
     *
     * @return
     */
    public int getGroups() {
        return groups;
    }
    
    @Override
    public int hashCode()
    {
        return 73 * code + id;
    }
    
    @Override
    public boolean equals(Object otherIn)
    {
        if(!(otherIn instanceof OpAction)) return false;
        OpAction other = (OpAction) otherIn;
        if((this.code == other.code) && (this.id == other.id)) return true;
        return false;
    }
}
