package com.sudicode.tunejar.config;

import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public class TestDefaults {

	public static final Path RESOURCES;

	/**
	 * Maps sample music files to the URLs where they can be downloaded if
	 * missing.
	 */
	public static final Map<File, URL> SAMPLE_MUSIC_MAP;

	static {
		// Directories
		RESOURCES = Paths.get("src", "test", "resources");

		// Sample Music
		Map<File, URL> sampleMusicMap = new HashMap<>();
		Consumer<String> sampleMusicConsumer = (str) -> {
			try {
				String fileType = FilenameUtils.getExtension(str);
				if (fileType.equals("m4a")) {
					fileType = "mp4";
				}
				URL url = new URL("http://sudicode.com/tunejar/Sample-Music/" + fileType + "/" + str);
				sampleMusicMap.put(RESOURCES.resolve(fileType).resolve(str).toFile(), url);
			} catch (MalformedURLException e) {
				throw new RuntimeException(e);
			}
		};
		String[] sampleMusicArr = new String[] { "AfterDark.mp3", "Dubstep.mp3", "Highrider.mp3", "MorningCruise.mp3",
				"QueenOfTheNight.mp3", "CrunkKnight.m4a", "MeatballParade.m4a", "Cute.wav", "FunnySong.wav",
				"LittleIdea.wav" };
		for (String s : sampleMusicArr) {
			sampleMusicConsumer.accept(s);
		}
		SAMPLE_MUSIC_MAP = Collections.unmodifiableMap(sampleMusicMap);
	}

	private TestDefaults() {}

}

@@ -728,23 +728,25 @@
 usic
-Consume
+Registra
 r = (
-str
+file
 ) -%3E
@@ -806,19 +806,20 @@
 tension(
-str
+file
 );%0A%09%09%09%09i
@@ -961,19 +961,20 @@
 + %22/%22 + 
-str
+file
 );%0A%09%09%09%09s
@@ -1027,19 +1027,20 @@
 resolve(
-str
+file
 ).toFile
@@ -1155,19 +1155,21 @@
 pleMusic
-Arr
+Files
  = new S
@@ -1383,17 +1383,20 @@
 (String 
-s
+file
  : sampl
@@ -1405,11 +1405,13 @@
 usic
-Arr
+Files
 ) %7B%0A
@@ -1424,23 +1424,24 @@
 pleMusic
-Consume
+Registra
 r.accept
@@ -1441,17 +1441,20 @@
 .accept(
-s
+file
 );%0A%09%09%7D%0A%09

Update test defaults