package de.siphalor.was;

import de.siphalor.was.content.ContentManager;
import de.siphalor.was.content.pack.ContentPack;
import de.siphalor.was.content.pack.JarContentPack;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ContentTests {
	static ContentManager contentManager;
	static ContentPack contentPack;

	@BeforeAll
	public static void prepareAll() {
		contentManager = new ContentManager();
		contentPack = new JarContentPack("jar", "content");
		contentManager.addPack(contentPack);
	}

	@Test
	public void areLangsUpToDate() throws IOException {
		Properties properties = new Properties();
		InputStream inputStream = contentManager.getResource("lang/en_us.lang").orElseThrow().getInputStream();
		properties.load(inputStream);

		contentManager.getResources("lang", "lang").forEach(resource -> {
			if (!resource.getId().equals("lang/en_us.lang")) {
				Properties props = new Properties();
				Assertions.assertDoesNotThrow(() -> props.load(resource.getInputStream()));
				Assertions.assertEquals(properties.keySet(), props.keySet(), "Missing lang keys for " + resource.getId());
			}
		});
	}
}
