class ProjectRequestDocumentFactory {

	private static final Pattern PROJECT_TYPE_PATTERN = Pattern.compile("([a-z]*)-[a-z-]*");

	public ProjectRequestDocument createDocument(ProjectRequestEvent event) {<FILL_FUNCTION_BODY>}

	private String determineBuildSystem(ProjectRequest request) {
		Matcher typeMatcher = PROJECT_TYPE_PATTERN.matcher(request.getType());
		if (typeMatcher.matches()) {
			return typeMatcher.group(1);
		}
		return null;
	}

	private VersionInformation determineVersionInformation(ProjectRequest request) {
		Version version = Version.safeParse(request.getBootVersion());
		if (version != null && version.getMajor() != null) {
			return new VersionInformation(version);
		}
		return null;
	}

	private ClientInformation determineClientInformation(ProjectRequest request) {
		if (request instanceof WebProjectRequest webProjectRequest) {
			Agent agent = determineAgent(webProjectRequest);
			String ip = determineIp(webProjectRequest);
			String country = determineCountry(webProjectRequest);
			if (agent != null || ip != null || country != null) {
				return new ClientInformation(agent, ip, country);
			}
		}
		return null;
	}

	private Agent determineAgent(WebProjectRequest request) {
		String userAgent = (String) request.getParameters().get("user-agent");
		if (StringUtils.hasText(userAgent)) {
			return Agent.fromUserAgent(userAgent);
		}
		return null;
	}

	private String determineIp(WebProjectRequest request) {
		String candidate = (String) request.getParameters().get("cf-connecting-ip");
		return (StringUtils.hasText(candidate)) ? candidate : (String) request.getParameters().get("x-forwarded-for");
	}

	private String determineCountry(WebProjectRequest request) {
		String candidate = (String) request.getParameters().get("cf-ipcountry");
		if (StringUtils.hasText(candidate) && !"xx".equalsIgnoreCase(candidate)) {
			return candidate;
		}
		return null;
	}

}

		InitializrMetadata metadata = event.getMetadata();
		ProjectRequest request = event.getProjectRequest();
		ProjectRequestDocument document = new ProjectRequestDocument();
		document.setGenerationTimestamp(event.getTimestamp());
		document.setGroupId(request.getGroupId());
		document.setArtifactId(request.getArtifactId());
		document.setPackageName(request.getPackageName());
		document.setVersion(determineVersionInformation(request));
		document.setClient(determineClientInformation(request));

		document.setJavaVersion(request.getJavaVersion());
		if (StringUtils.hasText(request.getJavaVersion())
				&& metadata.getJavaVersions().get(request.getJavaVersion()) == null) {
			document.triggerError().setJavaVersion(true);
		}

		document.setLanguage(request.getLanguage());
		if (StringUtils.hasText(request.getLanguage()) && metadata.getLanguages().get(request.getLanguage()) == null) {
			document.triggerError().setLanguage(true);
		}

		document.setPackaging(request.getPackaging());
		if (StringUtils.hasText(request.getPackaging())
				&& metadata.getPackagings().get(request.getPackaging()) == null) {
			document.triggerError().setPackaging(true);
		}

		document.setType(request.getType());
		document.setBuildSystem(determineBuildSystem(request));
		if (StringUtils.hasText(request.getType()) && metadata.getTypes().get(request.getType()) == null) {
			document.triggerError().setType(true);
		}

		// Let's not rely on the resolved dependencies here
		List<String> dependencies = new ArrayList<>(request.getDependencies());
		List<String> validDependencies = dependencies.stream()
			.filter((id) -> metadata.getDependencies().get(id) != null)
			.collect(Collectors.toList());
		document.setDependencies(new DependencyInformation(validDependencies));
		List<String> invalidDependencies = dependencies.stream()
			.filter((id) -> (!validDependencies.contains(id)))
			.collect(Collectors.toList());
		if (!invalidDependencies.isEmpty()) {
			document.triggerError().triggerInvalidDependencies(invalidDependencies);
		}

		// Let's make sure that the document is flagged as invalid no matter what
		if (event instanceof ProjectFailedEvent failed) {
			ErrorStateInformation errorState = document.triggerError();
			if (failed.getCause() != null) {
				errorState.setMessage(failed.getCause().getMessage());
			}
		}
		return document;
	
<no_super_class>