/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package scriptbuilder.structures.events;

import java.util.ArrayList;
import scriptbuilder.structures.ELEMENT;
import scriptbuilder.structures.I_XML_Writable;
import scriptbuilder.structures.ScriptEvent;
import scriptbuilder.structures.XMLBuilder;

/**
 * Data model for a CMS evaluatiion event. A CMS event has a location, a set of
 * messages, an ID, and a type. It also is an evaluation event.
 *
 * @author Bryan McGuffin
 */
public class CMSEvaluationEvent extends ScriptEvent implements I_EvaluationEvent, I_XML_Writable
{

    /**
     * Constructor.
     */
    public CMSEvaluationEvent()
    {
        super(ScriptEventType.CMS_EVAL_EVENT);
    }

    public String location = "";

    public ArrayList<String> message = new ArrayList<String>();

    public String cmsID = "";

    public String cmsType = "";

    public ArrayList<String> expectedAction = new ArrayList<String>();

    @Override
    public ArrayList<String> getExpectedActions()
    {
        return expectedAction;
    }

    @Override
    public void addAction(String act)
    {
        expectedAction.add(act);
    }

    @Override
    public void updateAction(int index, String act)
    {
        expectedAction.set(index, act);
    }

    @Override
    public void removeAction(int index)
    {
        expectedAction.remove(index);
    }

    @Override
    public String toXML()
    {
        String output = XMLBuilder.openTag(ELEMENT.CMS_EVALUATION.tag + " cmsID=\"" + cmsID + "\" type=\"" + cmsType + "\"");
        output += XMLBuilder.simpleTag(location, ELEMENT.LOCATION);

        if (message.size() > 0)
        {
            output += XMLBuilder.openTag(ELEMENT.SAMPLE_MESSAGE.tag);
            for (String str : message)
            {
                if (str == null)
                {
                    str = "";
                }
                output += XMLBuilder.simpleTag(str, ELEMENT.CMS_LINE);
            }
            output += XMLBuilder.closeTag(ELEMENT.SAMPLE_MESSAGE.tag);
        }

        output += XMLBuilder.closeTag(ELEMENT.CMS_EVALUATION.tag);

        return output;
    }
}
