package com.ibm.emb.junit;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * this class provides Helper functionality to prepare comlex media on the test
 * client for usage in testcases
 */
public class ComplexMediaLocationInfo {

    protected EMBTestConfiguration tstCfg = null;

    public static final int MEDIAGPL1 = 1;

    public static final int MEDIAGPL2 = 2;

    protected String extension = "";

    protected int mediaID = 0;

    URL rootURL = null;

    File rootFile = null;

    URL[] childURLs = null;

    File[] childFiles = null;

    /**
     * contructor
     */
    public ComplexMediaLocationInfo(int arg1) throws MalformedURLException, IOException {
        this.tstCfg = EMBTestConfiguration.instance();
        this.mediaID = arg1;
        switch (mediaID) {
            case (MEDIAGPL1):
                prepareGPL1();
                break;
            case (MEDIAGPL2):
                prepareGPL2();
                break;
            default:
                EMBStaticHelper.testError("no suitable mediaID specified in " + this.getClass().getName());
                break;
        }

    }

    protected void prepareGPL1() throws MalformedURLException, IOException {
        rootFile = new File(tstCfg.getMediaDir() + File.separator + tstCfg.getPlaylistName1());
        File C1 = new File(tstCfg.getMediaDir() + File.separator + "Gpl" + File.separator + "testPlaylist1"
                + File.separator + "testPlaylist1_1.jpg");
        File C2 = new File(tstCfg.getMediaDir() + File.separator + "Gpl" + File.separator + "testPlaylist1"
                + File.separator + "testPlaylist1_2.bmp");
        File C3 = new File(tstCfg.getMediaDir() + File.separator + "Gpl" + File.separator + "testPlaylist1"
                + File.separator + "testPlaylist1_3.jpg");
        this.childFiles = new File[] {C1, C2, C3};
        // removce /c:
        this.rootURL = new URL("file", tstCfg.getTestClientIPAddress(),  tstCfg.getMediaDir() + "/"
                + tstCfg.getPlaylistName1());
        URL C1Url = new URL("file", tstCfg.getTestClientIPAddress(),  tstCfg.getMediaDir()
                + "/Gpl/testPlaylist1/testPlaylist1_1.jpg");
        URL C2Url = new URL("file", tstCfg.getTestClientIPAddress(),  tstCfg.getMediaDir()
                + "/Gpl/testPlaylist1/testPlaylist1_2.jpg");
        URL C3Url = new URL("file", tstCfg.getTestClientIPAddress(),  tstCfg.getMediaDir()
                + "/Gpl/testPlaylist1/testPlaylist1_3.jpg");
        this.childURLs = new URL[] {C1Url, C2Url, C3Url};
        this.extension = ".gpl";
    }

    protected void prepareGPL2() throws MalformedURLException, IOException {
        rootFile = new File(tstCfg.getMediaDir() + File.separator + tstCfg.getPlaylistName2());
        File C1 = new File(tstCfg.getMediaDir() + File.separator + "Gpl" + File.separator + "testPlaylist1"
                + File.separator + "testPlaylist1_1.jpg");

        this.childFiles = new File[] {C1};
        // removce /c:
        this.rootURL = new URL("file", tstCfg.getTestClientIPAddress(),  tstCfg.getMediaDir() + "/"
                + tstCfg.getPlaylistName2());
        URL C1Url = new URL("file", tstCfg.getTestClientIPAddress(),  tstCfg.getMediaDir()
                + "/Gpl/testPlaylist1/testPlaylist1_1.jpg");

        this.childURLs = new URL[] {C1Url};
        this.extension = ".gpl";
    }

    /**
     * Gets the rootURL
     * @return Returns a URL
     */
    public URL getRootURL() {
        return rootURL;
    }

    /**
     * Sets the rootURL
     * @param rootURL The rootURL to set
     */
    public void setRootURL(URL rootURL) {
        this.rootURL = rootURL;
    }

    /**
     * Gets the rootFile
     * @return Returns a File
     */
    public File getRootFile() {
        return rootFile;
    }

    /**
     * Sets the rootFile
     * @param rootFile The rootFile to set
     */
    public void setRootFile(File rootFile) {
        this.rootFile = rootFile;
    }

    /**
     * Gets the extension
     * @return Returns a String
     */
    public String getExtension() {
        return extension;
    }

    /**
     * Sets the extension
     * @param extension The extension to set
     */
    public void setExtension(String extension) {
        this.extension = extension;
    }

    /**
     * Gets the childURLs
     * @return Returns a URL[]
     */
    public URL[] getChildURLs() {
        return childURLs;
    }

    /**
     * Sets the childURLs
     * @param childURLs The childURLs to set
     */
    public void setChildURLs(URL[] childURLs) {
        this.childURLs = childURLs;
    }

    /**
     * Gets the childFiles
     * @return Returns a File[]
     */
    public File[] getChildFiles() {
        return childFiles;
    }

    /**
     * Sets the childFiles
     * @param childFiles The childFiles to set
     */
    public void setChildFiles(File[] childFiles) {
        this.childFiles = childFiles;
    }
}