class EurekaMetadataParser {

    public static Map<String, String> generateMetadata(String serviceId, ApiInfo apiInfo) {
        Map<String, String> metadata = new HashMap<>();
        String encodedGatewayUrl = UrlUtils.getEncodedUrl(apiInfo.getGatewayUrl());

        if (apiInfo.getGatewayUrl() != null) {
            metadata.put(String.format(THREE_STRING_MERGE_FORMAT, API_INFO, encodedGatewayUrl, API_INFO_GATEWAY_URL), apiInfo.getGatewayUrl());
        }

        if (apiInfo.getVersion() != null) {
            metadata.put(String.format(THREE_STRING_MERGE_FORMAT, API_INFO, encodedGatewayUrl, API_INFO_VERSION), apiInfo.getVersion());
        }

        if (apiInfo.getSwaggerUrl() != null) {
            validateUrl(apiInfo.getSwaggerUrl(),
                () -> String.format("The Swagger URL \"%s\" for service %s is not valid", apiInfo.getSwaggerUrl(), serviceId)
            );

            metadata.put(String.format(THREE_STRING_MERGE_FORMAT, API_INFO, encodedGatewayUrl, API_INFO_SWAGGER_URL), apiInfo.getSwaggerUrl());
        }

        if (apiInfo.getDocumentationUrl() != null) {
            validateUrl(apiInfo.getDocumentationUrl(),
                () -> String.format("The documentation URL \"%s\" for service %s is not valid", apiInfo.getDocumentationUrl(), serviceId)
            );

            metadata.put(String.format(THREE_STRING_MERGE_FORMAT, API_INFO, encodedGatewayUrl, API_INFO_DOCUMENTATION_URL), apiInfo.getDocumentationUrl());
        }

        return metadata;
    }

}