import { Http, http } from '../../platform/net/http.js';
import { GSplatOctreeResource } from '../../scene/gsplat-unified/gsplat-octree.resource.js';

class GSplatOctreeParser {
		constructor(app, maxRetries){
				this.app = app;
				this.maxRetries = maxRetries;
		}
		load(url, callback, asset) {
				if (typeof url === 'string') {
						url = {
								load: url,
								original: url
						};
				}
				const options = {
						retry: this.maxRetries > 0,
						maxRetries: this.maxRetries,
						responseType: Http.ResponseType.JSON
				};
				http.get(url.load, options, (err, data)=>{
						if (!err) {
								const resource = new GSplatOctreeResource(asset.file.url, data);
								callback(null, resource);
						} else {
								callback(`Error loading gsplat octree: ${url.original} [${err}]`);
						}
				});
		}
}

export { GSplatOctreeParser };
