package speiger.src.coreengine.assets.api;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.util.List;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import speiger.src.coreengine.assets.impl.parsers.Buffers;
import speiger.src.coreengine.assets.impl.parsers.Checksums;
import speiger.src.coreengine.assets.impl.parsers.Closables;
import speiger.src.coreengine.assets.impl.parsers.Serialized;

public interface IAsset {
	public IAssetPackage owner();
	public ID location();
	
	public InputStream stream() throws IOException;
	public default ByteBuffer bytes() throws IOException { return parse(Buffers.HEAP); }
	public default BufferedReader reader() throws IOException { return parse(Closables.READER); }
	public default SeekableByteChannel channel() throws IOException { return parse(Closables.BYTE_CHANNEL); }
	public default List<String> lines() throws IOException { return parse(Serialized.LINES); }
	public default JsonObject jsonObj() throws IOException { return parse(Serialized.JSON_OBJ); }
	public default JsonArray jsonArray() throws IOException { return parse(Serialized.JSON_ARRAY); }
	
	public default String crc() throws IOException { return parse(Checksums.CRC); }
	public default String sha256() throws IOException { return parse(Checksums.SHA_256); }
	
	public <T> T parse(IAssetParser<T> parser) throws IOException;
}
