package turgen.plugin;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import turgen.generator.PulseCrate;
import turgen.playlist.AbstractPlayListItem;

/**Simple Playlist item*/
public class SimplePlaylistItem extends AbstractPlayListItem {
    
    
    /**Header - file name*/
    public String fname=null;
    
    /** Conversion type*/
    public int conversionType=-1;
    
    /** Loader*/
    public int loader=-1;
    
    public SimplePlaylistItem(String inF,String outF,PulseCrate speed,String fname,int[] sList) {
       this (inF,outF,speed,fname,sList,-1,-1);
    }
    
    public SimplePlaylistItem(String inF,String outF,PulseCrate speed,String fname,int[] sList,int cType,int ldr) {
    
        this.inFile=inF;
        this.outFile=outF;
        this.pulses=speed;
        
        this.silenceList=sList;
        this.fname=fname;
        this.conversionType=cType;
        this.loader=ldr;
    }
    
    public String toString() {
        return fname;
    }
    
    /**Prazdna instance*/
    public SimplePlaylistItem() {
        
    }
    
    public boolean validate() {
        if (this.inFile==null) return false;
        if (this.outFile==null) this.outFile="";
        if (this.fname==null) this.fname="NONAME";
        if (this.pulses==null) return false;
        if (this.silenceList==null) silenceList=new int[0];
        return true;
    }
    
    public AbstractPlayListItem getClonedCopy() {
        
        int[] pausesCopy=null;
        PulseCrate pulsesCopy = null;
        
        if (silenceList!=null) {
            pausesCopy = (int[])this.silenceList.clone();
        }
        if (pulses!=null) {
            pulsesCopy = pulses.getCopy();
        }
        SimplePlaylistItem item = new SimplePlaylistItem(inFile,outFile,pulsesCopy,fname,pausesCopy);
        copyBasics(item);
        return item;
    }

    
    public void saveToStream(DataOutputStream dos) throws Exception {
        saveBasics(dos);
        dos.writeUTF(fname);
        dos.writeInt(conversionType);
        dos.writeInt(loader);
        
    }

    
    public void loadFromStream(DataInputStream dis, int version) throws Exception {
        loadBasics(dis);
        fname=dis.readUTF();
        conversionType=dis.readInt();
        loader=dis.readInt();
    }
    
}
