/*
 * 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 CHP radio event. A CHP radio transmission has a
 * conversation, with dialog between a field unit and a dispatch center. It also
 * has an audio file which has that conversation acted out.
 *
 * @author Bryan McGuffin
 */
public class CHPRadioEvent extends ScriptEvent implements I_XML_Writable, I_AudioEvent
{

    /**
     * Constructor.
     */
    public CHPRadioEvent()
    {
        super(ScriptEventType.CHP_RADIO_EVENT);
    }

    /**
     * List of the lines of dialog in this event.
     */
    public ArrayList<String> lines = new ArrayList<String>();

    /**
     * List of the corresponding roles for each line of dialog.
     */
    public ArrayList<String> roles = new ArrayList<String>();

    /**
     * Path for the audio file to be played during this event.
     */
    public String radioFile = "";
    
    /**
     * ID
     */
    public String id = "";
    
    
    /**
     * Returns the contents of the CHPRadioEvent to make recording easier.
     * @return a string with the script to be said 
     */
    public String toScriptFile()
    {
        String fileContents = "";
        for(int lineIndex=0;lineIndex<lines.size();lineIndex++)
        {
            fileContents += roles.get(lineIndex) + " " + lines.get(lineIndex) + "\n";
        }
        return fileContents;
    }
    
    @Override
    public String getFileName()
    {
        return radioFile;
    }
    
    @Override
    public String getID()
    {
        return id;
    }
    
    @Override
    public void setID(String id)
    {
        this.id = id;
    }
    
    @Override
    public void setFileName(String s)
    {
        radioFile = s;
    }
    
    @Override
    public void removeThis()
    {
        this.slice.events.remove(this);
        //removes the correct AudioEvent when this CHPRadioEvent is removed
        this.slice.removeCorrespondingAudioEvent(this);
        this.slice.checkEmpty();
    }
    
    @Override
    public String toXML()
    {
        String output = XMLBuilder.openTag(ELEMENT.CHP_RADIO.tag + " RadioFile=\"" + radioFile + "\"");
        output += XMLBuilder.openTag(ELEMENT.DIALOG.tag);

        for (int i = 0; i < lines.size(); i++)
        {
            output += XMLBuilder.openTag(ELEMENT.LINE.tag + " Role=\"" + roles.get(i) + "\"");
            output += lines.get(i);
            output += XMLBuilder.closeTag(ELEMENT.LINE.tag);
        }

        output += XMLBuilder.closeTag(ELEMENT.DIALOG.tag);
        output += XMLBuilder.closeTag(ELEMENT.CHP_RADIO.tag);

        return output;
    }
}
