package it.micegroup.voila2.cartridge.library.javaservice;

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

import org.eclipse.uml2.uml.Type;
/**
 * 
 * This class mapped uml-type with name function generate<type>Specification
 * 
 * @author Luca Barone
 *
 */
public class SpecificationFilterUtils {

	private static final String DEFAULT_FILTER_GENERIC = "generateSpecification";
	private static final String DEFAULT_FILTER_RANGE = "generateRangeSpecification";
	private static final String DEFAULT_FILTER_STRING = "generateStringSpecification";
	
	
	private static Map<String, String> MAP_DEFAULT_JAVA_TYPE = new HashMap<>();
	
	
	static {
		MAP_DEFAULT_JAVA_TYPE.put("Datetime", DEFAULT_FILTER_RANGE);
		MAP_DEFAULT_JAVA_TYPE.put("Date", DEFAULT_FILTER_RANGE);
		MAP_DEFAULT_JAVA_TYPE.put("Integer", DEFAULT_FILTER_RANGE);
		MAP_DEFAULT_JAVA_TYPE.put("Code", DEFAULT_FILTER_RANGE);
		MAP_DEFAULT_JAVA_TYPE.put("Value", DEFAULT_FILTER_RANGE);
		MAP_DEFAULT_JAVA_TYPE.put("Currency", DEFAULT_FILTER_RANGE);
		MAP_DEFAULT_JAVA_TYPE.put("String", DEFAULT_FILTER_STRING);
		MAP_DEFAULT_JAVA_TYPE.put("Boolean", DEFAULT_FILTER_GENERIC);
		MAP_DEFAULT_JAVA_TYPE.put("Long", DEFAULT_FILTER_RANGE);
		MAP_DEFAULT_JAVA_TYPE.put("Number", DEFAULT_FILTER_RANGE);
	}
	
	/**
	 * get the name function generate<type>Specification based on the input type.
	 * 
	 * @author Luca Barone <luca.barone@micegroup.it>
	 * @param type
	 * @return
	 */
	public String getSpecification(Type type) {

		String umlType = type.getName();
		String javaTypeName = MAP_DEFAULT_JAVA_TYPE.get(umlType);
		if(javaTypeName == null)
			// se non è presente nel Map consentimo un filter generico!
			return DEFAULT_FILTER_GENERIC;
		return javaTypeName;
	}

}
