/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.data.module.registry;

import java.util.HashMap;
import java.util.Map;

import org.springframework.cloud.data.core.ModuleCoordinates;

/**
 * @author Mark Fisher
 */
public class StubModuleRegistry implements ModuleRegistry {

	private static final String GROUP_ID = "org.springframework.cloud.stream.module";

	private static final String VERSION = "1.0.0.BUILD-SNAPSHOT";

	private final Map<String, ModuleCoordinates> sources = new HashMap<>();

	private final Map<String, ModuleCoordinates> sinks = new HashMap<>();

	public StubModuleRegistry() {
		sources.put("time", ModuleCoordinates.parse(String.format("%s:%s:%s", GROUP_ID, "time-source", VERSION)));
		sinks.put("log", ModuleCoordinates.parse(String.format("%s:%s:%s", GROUP_ID, "log-sink", VERSION)));
	}

	@Override
	public ModuleCoordinates findByNameAndType(String name, String type) {
		if ("source".equals(type)) {
			return sources.get(name);
		}
		if ("sink".equals(type)) {
			return sinks.get(name);
		}
		throw new UnsupportedOperationException("only 'source' and 'sink' types are currently supported");
	}

}

@@ -1218,22 +1218,23 @@
 %22time%22, 
-Module
+default
 Coordina
@@ -1240,51 +1240,12 @@
 ates
-.parse(String.format(%22%25s:%25s:%25s%22, GROUP_ID, 
+For(
 %22tim
@@ -1253,26 +1253,16 @@
 -source%22
-, VERSION)
 ));%0A%09%09si
@@ -1276,22 +1276,23 @@
 (%22log%22, 
-Module
+default
 Coordina
@@ -1298,71 +1298,85 @@
 ates
-.parse(String.format(%22%25s:%25s:%25s%22, GROUP_ID, %22log-sink%22, VERSION)
+For(%22log-sink%22));%0A%09%09sinks.put(%22counter%22, defaultCoordinatesFor(%22counter-sink%22
 ));%0A
@@ -1691,10 +1691,175 @@
 %22);%0A%09%7D%0A%0A
+%09private ModuleCoordinates defaultCoordinatesFor(String moduleName) %7B%0A%09%09return ModuleCoordinates.parse(String.format(%22%25s:%25s:%25s%22, GROUP_ID, moduleName, VERSION));%0A%09%7D%0A
 %7D%0A

add counter-sink to stub registry