package speiger.src.coreengine.assets.manager;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Executor;

import speiger.src.collections.objects.utils.ObjectSets;
import speiger.src.coreengine.assets.api.IAssetPackage;
import speiger.src.coreengine.assets.api.ID;
import speiger.src.coreengine.assets.api.IResourceListener;
import speiger.src.coreengine.assets.providers.BaseProvider;
import speiger.src.coreengine.assets.providers.LayeredProvider;
import speiger.src.coreengine.assets.providers.SingleProvider;

public class ReloadBuilder {
	Executor mainRunner = Runnable::run;
	Executor taskRunner = Runnable::run;
	Executor syncRunner = Runnable::run;
	Set<ID> filter = ObjectSets.empty();
	Optional<BaseProvider> packages = Optional.empty();
	Optional<List<IResourceListener>> listeners = Optional.empty();
	
	public ReloadBuilder withFilter(Set<ID> filter) {
		this.filter = Objects.requireNonNull(filter);
		return this;
	}
	
	public ReloadBuilder withMainThread(Executor main) {
		mainRunner = Objects.requireNonNull(main);
		return this;
	}
	
	public ReloadBuilder withTasks(Executor tasks) {
		taskRunner = Objects.requireNonNull(tasks);
		return this;
	}
	
	public ReloadBuilder withSync(Executor sync) {
		syncRunner = Objects.requireNonNull(sync);
		return this;
	}
	
	public ReloadBuilder withPackages(List<IAssetPackage> packages) {
		return withPackages(new LayeredProvider(packages));
	}
	
	public ReloadBuilder withPackages(IAssetPackage pack) {
		return withPackages(new SingleProvider(pack));
	}
	
	public ReloadBuilder withPackages(BaseProvider packages) {
		this.packages = Optional.ofNullable(packages);
		return this;
	}
	
	public ReloadBuilder withListener(List<IResourceListener> listeners) {
		this.listeners = Optional.ofNullable(listeners);
		return this;
	}
}