// Path: core/src/main/java/se/tfiskgul/mux2fs/Constants.java
// public static final int MUX_WAIT_LOOP_MS = 500;
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/Constants.java
// public static final int SUCCESS = 0;
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/Sleeper.java
// @FunctionalInterface
// public interface Sleeper {
// 
// 	void sleep(int millis)
// 			throws InterruptedException;
// }


import static se.tfiskgul.mux2fs.Constants.MUX_WAIT_LOOP_MS;
import static se.tfiskgul.mux2fs.Constants.SUCCESS;
import static se.tfiskgul.mux2fs.mux.Muxer.State.FAILED;
import static se.tfiskgul.mux2fs.mux.Muxer.State.NOT_STARTED;
import static se.tfiskgul.mux2fs.mux.Muxer.State.RUNNING;
import static se.tfiskgul.mux2fs.mux.Muxer.State.SUCCESSFUL;
import java.io.File;
import java.io.IOException;
import java.nio.file.AccessMode;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
import se.tfiskgul.mux2fs.fs.base.Sleeper;

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Muxer other = (Muxer) obj;
		return Objects.equals(mkv, other.mkv) && Objects.equals(output, other.output) && Objects.equals(srt, other.srt)
				&& Objects.equals(tempDir, other.tempDir);
	}

	@Override
	public String toString() {
		return "Muxer [mkv=" + mkv + ", srt=" + srt + ", tempDirPath=" + tempDir + ", output=" + output + ", state=" + state + ", process=" + process + "]";
	}

	public Path getMkv() {
		return mkv;
	}

	public boolean waitForOutput() {
		final File file = output.toFile();
		while (!file.isFile() && state() == RUNNING) {
			try {
// Path: core/src/main/java/se/tfiskgul/mux2fs/Constants.java
// public static final int MUX_WAIT_LOOP_MS = 500;
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/Constants.java
// public static final int SUCCESS = 0;
// 
// Path: core/src/main/java/se/tfiskgul/mux2fs/fs/base/Sleeper.java
// @FunctionalInterface
// public interface Sleeper {
// 
// 	void sleep(int millis)
// 			throws InterruptedException;
// }


// Path: core/src/main/java/se/tfiskgul/mux2fs/mux/Muxer.java
import static se.tfiskgul.mux2fs.Constants.MUX_WAIT_LOOP_MS;
import static se.tfiskgul.mux2fs.Constants.SUCCESS;
import static se.tfiskgul.mux2fs.mux.Muxer.State.FAILED;
import static se.tfiskgul.mux2fs.mux.Muxer.State.NOT_STARTED;
import static se.tfiskgul.mux2fs.mux.Muxer.State.RUNNING;
import static se.tfiskgul.mux2fs.mux.Muxer.State.SUCCESSFUL;
import java.io.File;
import java.io.IOException;
import java.nio.file.AccessMode;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
import se.tfiskgul.mux2fs.fs.base.Sleeper;


	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Muxer other = (Muxer) obj;
		return Objects.equals(mkv, other.mkv) && Objects.equals(output, other.output) && Objects.equals(srt, other.srt)
				&& Objects.equals(tempDir, other.tempDir);
	}

	@Override
	public String toString() {
		return "Muxer [mkv=" + mkv + ", srt=" + srt + ", tempDirPath=" + tempDir + ", output=" + output + ", state=" + state + ", process=" + process + "]";
	}

	public Path getMkv() {
		return mkv;
	}

	public boolean waitForOutput() {
		final File file = output.toFile();
		while (!file.isFile() && state() == RUNNING) {
			try {
				sleeper.sleep(MUX_WAIT_LOOP_MS);