class ExposureCustomizer implements CamelKIntegrationCustomizer {

    @Override
    public Integration customize(IntegrationDeployment deployment, Integration integration, EnumSet<Exposure> exposure) {
        IntegrationSpec.Builder spec = new IntegrationSpec.Builder();
        if (integration.getSpec() != null) {
            spec = spec.from(integration.getSpec());
        }

        if (exposure.contains(Exposure.SERVICE)) {
            spec.putTraits(
                "service",
                new TraitSpec.Builder()
                    .putConfiguration("enabled", "true")
                    .putConfiguration("auto", "false")
                    .putConfiguration("port", Integer.toString(OpenShiftService.INTEGRATION_SERVICE_PORT))
                    .build()
            );

            spec.addConfiguration(
                new ConfigurationSpec.Builder()
                    .type(PROPERTY)
                    .value("customizer.health.enabled=true")
                    .build()
            );
            spec.addConfiguration(
                new ConfigurationSpec.Builder()
                    .type(PROPERTY)
                    .value("customizer.health.path=/actuator/health")
                    .build()
            );
            spec.addConfiguration(
                new ConfigurationSpec.Builder()
                    .type(PROPERTY)
                    .value("customizer.platform-http.enabled=true")
                    .build()
            );
            spec.addConfiguration(
                new ConfigurationSpec.Builder()
                    .type(PROPERTY)
                    .value("customizer.platform-http.bind-port=" + OpenShiftService.INTEGRATION_SERVICE_PORT)
                    .build()
            );

            spec.addConfiguration(PROPERTY, "camel.rest.contextPath=/");
            spec.addConfiguration(PROPERTY, "camel.rest.component=servlet");
            spec.addConfiguration(PROPERTY, "camel.rest.endpointProperty.headerFilterStrategy=syndesisHeaderStrategy");
        }

        if (exposure.contains(Exposure.ROUTE)) {
            spec.putTraits(
                "route",
                new TraitSpec.Builder()
                    .putConfiguration("enabled", "true")
                    .putConfiguration("tls-termination", "edge")
                    .build()
            );
        }

        if (exposure.contains(Exposure._3SCALE)) {
            if (integration.getMetadata().getLabels() == null) {
                integration.getMetadata().setLabels(new HashMap<>());
            }
            if (integration.getMetadata().getAnnotations() == null) {
                integration.getMetadata().setAnnotations(new HashMap<>());
            }

            integration.getMetadata().getLabels().put("discovery.3scale.net", "true");
            integration.getMetadata().getAnnotations().put("discovery.3scale.net/scheme", "http");
            integration.getMetadata().getAnnotations().put("discovery.3scale.net/port", "8080");
            integration.getMetadata().getAnnotations().put("discovery.3scale.net/description-path", "/openapi.json");
        }

        integration.setSpec(spec.build());

        return integration;
    }

}