package speiger.src.coreengine.platform.input.events;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Iterator;

import speiger.src.collections.objects.utils.ObjectIterators;

public class FileEvents {
	public static class Drop extends MouseEvent implements Iterable<DroppedFile> {
		DroppedFile[] files;
		
		public Drop(long window, int x, int y, Path[] files) {
			super(window, x, y);
			this.files = new DroppedFile[files.length];
			for(int i = 0,m=files.length;i<m;i++) {
				String name = files[i].getFileName().toString();
				this.files[i] = new DroppedFile(files[i], name, name.substring(name.lastIndexOf(".")+1));
			}
		}
		
		@Override
		public Iterator<DroppedFile> iterator() { return ObjectIterators.wrap(files); }		
		public int size() { return files.length; }
		public DroppedFile get() { return files[0]; }
		public DroppedFile get(int index) { return files[index]; }
	}
	
	public record DroppedFile(Path path, String name, String extension) {
		public boolean isFolder() { return Files.isDirectory(path); }
		public boolean isFile() { return Files.isRegularFile(path); }
	}
}
