/**
 * as_app_validate_screenshots:
 **/
static void
as_app_validate_screenshots (AsApp *app, AsAppValidateHelper *helper)
{
	AsScreenshot *ss;
	GPtrArray *screenshots;
	gboolean screenshot_has_default = FALSE;
	guint number_screenshots_max = 5;
	guint number_screenshots_min = 1;
	guint i;

	/* relax the requirements a bit */
	if ((helper->flags & AS_APP_VALIDATE_FLAG_RELAX) > 0) {
		number_screenshots_max = 10;
		number_screenshots_min = 0;
	}

	/* metainfo doesn't require any screenshots */
	if (as_app_get_source_kind (app) == AS_APP_SOURCE_KIND_METAINFO)
		number_screenshots_min = 0;

	/* only for AppData and AppStream */
	if (as_app_get_source_kind (app) == AS_APP_SOURCE_KIND_DESKTOP)
		return;

	screenshots = as_app_get_screenshots (app);
	if (screenshots->len < number_screenshots_min) {
		ai_app_validate_add (helper->probs,
				     AS_PROBLEM_KIND_STYLE_INCORRECT,
				     "Not enough <screenshot> tags");
	}
	if (screenshots->len > number_screenshots_max) {
		ai_app_validate_add (helper->probs,
				     AS_PROBLEM_KIND_STYLE_INCORRECT,
				     "Too many <screenshot> tags");
	}
	for (i = 0; i < screenshots->len; i++) {
		ss = g_ptr_array_index (screenshots, i);
		as_app_validate_screenshot (ss, helper);
		if (as_screenshot_get_kind (ss) == AS_SCREENSHOT_KIND_DEFAULT) {
			if (screenshot_has_default) {
				ai_app_validate_add (helper->probs,
						     AS_PROBLEM_KIND_MARKUP_INVALID,
						     "<screenshot> has more than one default");
			}
			screenshot_has_default = TRUE;
			continue;
		}
	}
	if (screenshots->len > 0 && !screenshot_has_default) {
		ai_app_validate_add (helper->probs,
				     AS_PROBLEM_KIND_MARKUP_INVALID,
				     "<screenshots> has no default <screenshot>");
	}
}
static void
as_app_validate_screenshots (AsApp *app, AsAppValidateHelper *helper)
{
	AsFormat *format;
	AsScreenshot *ss;
	GPtrArray *screenshots;
	gboolean screenshot_has_default = FALSE;
	guint number_screenshots_max = 25;
	guint number_screenshots_min = 1;
	guint i;

	/* relax the requirements a bit */
	if ((helper->flags & AS_APP_VALIDATE_FLAG_RELAX) > 0) {
		number_screenshots_max = 10;
		number_screenshots_min = 0;
	}

	/* firmware does not need screenshots */
	if (as_app_get_kind (app) == AS_APP_KIND_FIRMWARE ||
	    as_app_get_kind (app) == AS_APP_KIND_DRIVER ||
	    as_app_get_kind (app) == AS_APP_KIND_RUNTIME ||
	    as_app_get_kind (app) == AS_APP_KIND_ADDON ||
	    as_app_get_kind (app) == AS_APP_KIND_LOCALIZATION)
		number_screenshots_min = 0;

	/* metainfo and inf do not require any screenshots */
	format = as_app_get_format_default (app);
	if (as_format_get_kind (format) == AS_FORMAT_KIND_METAINFO)
		number_screenshots_min = 0;

	/* only for AppData and AppStream */
	if (as_format_get_kind (format) == AS_FORMAT_KIND_DESKTOP)
		return;

	screenshots = as_app_get_screenshots (app);
	if (screenshots->len < number_screenshots_min) {
		ai_app_validate_add (helper,
				     AS_PROBLEM_KIND_STYLE_INCORRECT,
				     "Not enough <screenshot> tags, minimum is %u",
				     number_screenshots_min);
	}
	if (screenshots->len > number_screenshots_max) {
		ai_app_validate_add (helper,
				     AS_PROBLEM_KIND_STYLE_INCORRECT,
				     "Too many <screenshot> tags, maximum is %u",
				     number_screenshots_max);
	}
	for (i = 0; i < screenshots->len; i++) {
		ss = g_ptr_array_index (screenshots, i);
		as_app_validate_screenshot (ss, helper);
		if (as_screenshot_get_kind (ss) == AS_SCREENSHOT_KIND_DEFAULT) {
			if (screenshot_has_default) {
				ai_app_validate_add (helper,
						     AS_PROBLEM_KIND_MARKUP_INVALID,
						     "<screenshot> has more than one default");
			}
			screenshot_has_default = TRUE;
			continue;
		}
	}
	if (screenshots->len > 0 && !screenshot_has_default) {
		ai_app_validate_add (helper,
				     AS_PROBLEM_KIND_MARKUP_INVALID,
				     "<screenshots> has no default <screenshot>");
	}
}