// valac grilo-test.vala -o grilo-test --pkg grilo-0.3

void resolve_game () {
	var registry = Grl.Registry.get_default ();

	try {
		registry.load_all_plugins(true);
	}
	catch (Error e) {
		error (e.message);
	}

	var source = registry.lookup_source ("grl-gamefaqs");
	assert (source != null);

	var media = new Grl.Media ();
	media.set_title ("Strider");
	media.set_mime ("application/x-genesis-rom");

	var keys = Grl.MetadataKey.list_new (Grl.MetadataKey.THUMBNAIL,
	                                     Grl.MetadataKey.DESCRIPTION,
	                                     Grl.MetadataKey.EXTERNAL_URL,
	                                     Grl.MetadataKey.RATING,
	                                     Grl.MetadataKey.PUBLICATION_DATE,
	                                     Grl.MetadataKey.ORIGINAL_TITLE,
	                                     null);

	var options = new Grl.OperationOptions (null);
	options.set_resolution_flags (Grl.ResolutionFlags.FULL);

	print ("refs: %u\n", media.ref_count);

	try {
		source.resolve_sync (media, keys, options);
	}
	catch (Error e) {
		error (e.message);
	}

	print ("refs: %u\n", media.ref_count);

	return_if_fail (media.length (Grl.MetadataKey.THUMBNAIL) != 0);
	print ("%s\n", media.get_thumbnail_nth (0));

	print ("%s\n", media.get_description ());

	return_if_fail (media.length (Grl.MetadataKey.EXTERNAL_URL) != 0);
	print ("%s\n", media.get_external_url ());

	print ("%f\n", media.get_rating ());

	var date_time = media.get_publication_date ();
	print ("%d\n", date_time.get_year ());

	print ("%s\n", media.get_original_title ());
}

void main(string[] args) {
	Grl.init (ref args);

	resolve_game ();

	Grl.deinit ();
}
