package com.orange.config;

import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.servicebroker.model.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CatalogConfig {
	@Value("#{ systemEnvironment['SERVICES_ID_NAME'] }")
	private String name;
	@Value("#{ systemEnvironment['SERVICES_ID_DESCRIPTION'] }")
	private String description = "";
	@Value("#{ systemEnvironment['SERVICES_ID_BINDEABLE'] ?: true}")
	private boolean bindable;
	@Value("#{ systemEnvironment['PLAN_NAME'] ?: 'default' }")
	private String plan_name;
	@Value("#{ systemEnvironment['PLAN_DESCRIPTION'] ?: 'Default plan' }")
	private String plan_description;
	@Value("#{ systemEnvironment['PLAN_FREE'] ?: true}")
	private boolean plan_free;
	@Value("#{ systemEnvironment['SERVICES_ID_TAGS'] }")
	private String tagstr;
	
	@Bean
	public Catalog catalog(){
		List<ServiceDefinition> serviceDefinitions = new ArrayList<ServiceDefinition>();
		String service_id = "000d5d66-e95b-4c19-beaf-064becbd3ada";
		Map<String, Object> service_metadata = new HashMap<String, Object>();
		
		String plan_id = "101d240e-c36f-46e8-b35f-97d2f69bd185";
		Map<String, Object> plan_metadata = new HashMap<String, Object>();
		List<String> tags = new ArrayList<String>();
		if (tagstr != null) {
			tags = Arrays.asList(tagstr.split(","));
		}
		
		Plan plan = new Plan(plan_id, plan_name, plan_description, plan_metadata, plan_free);
		ServiceDefinition service = new ServiceDefinition(service_id, name, description, bindable, false, Collections.singletonList(plan), tags, service_metadata, null, null);
		serviceDefinitions.add(service);
		Catalog catalog = new Catalog(serviceDefinitions);
		return catalog;
	}

}

@@ -713,16 +713,814 @@
 ndable;%0A
+%09@Value(%22#%7B systemEnvironment%5B'SERVICES_ID_TAGS'%5D %7D%22)%0A%09private String tagstr;%0A%09%0A%09@Value(%22#%7B systemEnvironment%5B'SERVICES_ID_METADATA_DISPLAYNAME'%5D ?: systemEnvironment%5B'SERVICES_ID_NAME'%5D%7D%22)%0A%09private String meta_displayname;%0A%09@Value(%22#%7B systemEnvironment%5B'SERVICES_ID_METADATA_IMAGEURL'%5D ?: ''%7D%22)%0A%09private String meta_imageurl;%0A%09@Value(%22#%7B systemEnvironment%5B'SERVICES_ID_METADATA_SUPPORTURL'%5D ?: ''%7D%22)%0A%09private String meta_supporturl;%0A%09@Value(%22#%7B systemEnvironment%5B'SERVICES_ID_METADATA_DOCUMENTATIONURL'%5D ?: ''%7D%22)%0A%09private String meta_documentationurl;%0A%09@Value(%22#%7B systemEnvironment%5B'SERVICES_ID_METADATA_PROVIDERDISPLAYNAME'%5D ?: ''%7D%22)%0A%09private String meta_providerdisplayname;%0A%09@Value(%22#%7B systemEnvironment%5B'SERVICES_ID_METADATA_LONGDESCRIPTION'%5D ?: ''%7D%22)%0A%09private String meta_longdescription;%0A%0A%09%0A
 %09@Value(
@@ -1567,24 +1567,24 @@
 efault' %7D%22)%0A
-
 %09private Str
@@ -1817,35 +1817,39 @@
 onment%5B'
-SERVICES_ID_TAGS'%5D 
+PLAN_METADATA'%5D ?: '%7B%7D'
 %7D%22)%0A%09pri
@@ -1856,31 +1856,42 @@
 vate String 
-tagstr;
+plan_metadata;%0A%09%0A%09
 %0A%09%0A%09@Bean%0A%09p
@@ -2060,16 +2060,16 @@
 d3ada%22;%0A
-
 %09%09Map%3CSt
@@ -2132,16 +2132,384 @@
 ect%3E();%0A
+%09%09service_metadata.put(%22displayName%22, meta_displayname);%0A%09%09service_metadata.put(%22imageUrl%22, meta_imageurl);%0A%09%09service_metadata.put(%22longDescription%22, meta_longdescription);%0A%09%09service_metadata.put(%22providerDisplayName%22, meta_providerdisplayname);%0A%09%09service_metadata.put(%22documentationUrl%22, meta_documentationurl);%0A%09%09service_metadata.put(%22supportUrl%22, meta_supporturl);%0A
 %09%09%0A%09%09Str

add service metadata