package dk.itu.mario.engine;

import dk.itu.mario.MarioInterface.LevelGenerator;
import dk.itu.mario.level.generator.CustomizedLevelGenerator;
import dk.itu.mario.level.generator.MyLevelGenerator;
import dk.itu.mario.level.generator.PCGLevelGenerator;
import dk.itu.mario.level.generator.RandomLevelGenerator;

public class ParsedArgs {
	public static final String NO_GEN_ERR = "Generator class not specified (use generator=... argument).";
	
	//Default values per Play class:
	private boolean custom = false;
	private boolean videoCaptureEnabled = false;
	private int levelRandSeed = (int) (Math.random() * Integer.MAX_VALUE);
	private String generatorClass = "PCGLevel";
	private String videoFileName = "LevelGenerator";
	
	public LevelGenerator createLevelGenerator() {
		if (generatorClass == null) {
			throw new UnsupportedOperationException(NO_GEN_ERR);
		}
		if ("MyLevel".equals(generatorClass)) {
			return new MyLevelGenerator();
		} else if ("PCGLevel".equals(generatorClass)) {
			return new PCGLevelGenerator();
		} else if ("CustomizedLevel".equalsIgnoreCase(generatorClass)) {
			return new CustomizedLevelGenerator();
		} else if ("RandomLevel".equalsIgnoreCase(generatorClass)) {
			return new RandomLevelGenerator();
		} else {
			throw new UnsupportedOperationException("Cannot create LevelFactory for unrecognized class:" + generatorClass);
		}
	}

	public String getGeneratorClass() {
		return generatorClass;
	}
	
	public int getLevelRandSeed() {
		return levelRandSeed;
	}
	
	public String getVideoFileName() {
		return videoFileName;
	}
	
	public boolean isCustom() {
		return custom;
	}
	
	public boolean isGeneratorClassSet() {
		return generatorClass != null;
	}
	
	public boolean isVideoCaptureEnabled() {
		return videoCaptureEnabled;
	}
	
	public void setGeneratorClass(String generatorClass) {
		if (generatorClass == null) {
			throw new UnsupportedOperationException(NO_GEN_ERR);
		}
		
		this.generatorClass = generatorClass;
		
		if ("MyLevel".equals(generatorClass)) {
			custom = true;
		} else if ("CustomizedLevel".equalsIgnoreCase(generatorClass)) {
			custom = true;
		} else {
			custom = false;
		}
	}
	
	public void setVideoFileName(String videoFileName) {
		this.videoFileName = videoFileName;
		this.videoCaptureEnabled = true;
	}
	
	public boolean setLevelRandSeed(String randSeedString) {
		try {
			levelRandSeed = Integer.valueOf(randSeedString);
			return true;
		} catch (NumberFormatException nfe) {
			return false;
		}
	}
}