// Path: src/main/java/info/interactivesystems/gamificationengine/api/exeption/ApiError.java
// @ApplicationException
// public class ApiError extends WebApplicationException {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	/**
// 	 * 
// 	 * @param status
// 	 *            a HTTP status code.
// 	 * @param message
// 	 *            a description of the error cause.
// 	 */
// 	public ApiError(Response.Status status, String message) {
// 		this(status, message, new Object[] {});
// 	}
// 
// 	/**
// 	 * @param status
// 	 *            a HTTP status code
// 	 * @param message
// 	 *            a description of the error cause, may be a formatted string.
// 	 * @param args
// 	 *            for format string, may be zero, see {@link String#format test}
// 	 *            .
// 	 */
// 	public ApiError(Response.Status status, String message, Object... args) {
// 		super(ResponseSurrogate.of(status, null, Notification.of(String.format(message, args))));
// 	}
// }


import info.interactivesystems.gamificationengine.api.exeption.ApiError;
import info.interactivesystems.gamificationengine.api.validation.ValidListOfDigits;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.validation.constraints.NotNull;
import javax.ws.rs.core.Response;
package info.interactivesystems.gamificationengine.utils;




public class StringUtils {
	
	/**
	 * Converts a string of digits to list of integers.
	 * <p></p>
	 * Splits a comma separated list by a comma and trims each string. Collects to
	 * a list of Integers.
	 * 
	 * @param commaSeparatedList
	 *            The comma separated list.
	 * @return The list of single integers that were separated. 
	 */
	public static @NotNull List<Integer> stringArrayToIntegerList(@NotNull String commaSeparatedList) {
		String[] arrayList = commaSeparatedList.split(",");
		return Stream.of(arrayList).map(String::trim).collect(Collectors.mapping(Integer::valueOf, Collectors.toList()));
	}

	/**
	 * Checks if the passed value is a list of digists.
	 * 
	 * @param value
	 *            The value for validation.
	 * @return If valid the identity is returned.
	 */
	public static @NotNull String validateAsListOfDigits(@NotNull @ValidListOfDigits String value) {
		return value;
	}
	
	/**
	 * Checks if the passed value is "true", "t", "yes", "y", "sure", "aye", "ja" or "1". If this is the case it is 
	 * accepted as a value for "true" and so true is returned else false.
	 * 
	 * @param value
	 * 		The value that should be checked.
	 * @return
	 * 		Boolean value if the passed String is 
	 */
	public static boolean checkBoolean(String value){
		boolean result = "true".equalsIgnoreCase(value) || "t".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)
		|| "y".equalsIgnoreCase(value) || "sure".equalsIgnoreCase(value) || "aye".equalsIgnoreCase(value)
		|| "ja".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value);
		return result;
	}
	
	/**
	 * This method prints the ids of objects that should be deleted before a specific object can be deleted.
	 * 
	 * @param ids
	 * 			Ids of the objects that should be deleted first.
	 * @param objectToDelete
	 * 			The type of the object that should be deleted. This is only given by a String.
	 * @param type
	 * 			The type of the object that use the object, so it should be deleted before. This is only given 
	 * 			by a String.
	 */
	public static void printIdsForDeletion(List<String> ids, String objectToDelete, String type){
			String message = "This " +objectToDelete + " is still used. Please delete first " +  type + " with id: ";
			message += String.join(",", ids);
// Path: src/main/java/info/interactivesystems/gamificationengine/api/exeption/ApiError.java
// @ApplicationException
// public class ApiError extends WebApplicationException {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	/**
// 	 * 
// 	 * @param status
// 	 *            a HTTP status code.
// 	 * @param message
// 	 *            a description of the error cause.
// 	 */
// 	public ApiError(Response.Status status, String message) {
// 		this(status, message, new Object[] {});
// 	}
// 
// 	/**
// 	 * @param status
// 	 *            a HTTP status code
// 	 * @param message
// 	 *            a description of the error cause, may be a formatted string.
// 	 * @param args
// 	 *            for format string, may be zero, see {@link String#format test}
// 	 *            .
// 	 */
// 	public ApiError(Response.Status status, String message, Object... args) {
// 		super(ResponseSurrogate.of(status, null, Notification.of(String.format(message, args))));
// 	}
// }


// Path: src/main/java/info/interactivesystems/gamificationengine/utils/StringUtils.java
import info.interactivesystems.gamificationengine.api.exeption.ApiError;
import info.interactivesystems.gamificationengine.api.validation.ValidListOfDigits;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.validation.constraints.NotNull;
import javax.ws.rs.core.Response;

package info.interactivesystems.gamificationengine.utils;




public class StringUtils {
	
	/**
	 * Converts a string of digits to list of integers.
	 * <p></p>
	 * Splits a comma separated list by a comma and trims each string. Collects to
	 * a list of Integers.
	 * 
	 * @param commaSeparatedList
	 *            The comma separated list.
	 * @return The list of single integers that were separated. 
	 */
	public static @NotNull List<Integer> stringArrayToIntegerList(@NotNull String commaSeparatedList) {
		String[] arrayList = commaSeparatedList.split(",");
		return Stream.of(arrayList).map(String::trim).collect(Collectors.mapping(Integer::valueOf, Collectors.toList()));
	}

	/**
	 * Checks if the passed value is a list of digists.
	 * 
	 * @param value
	 *            The value for validation.
	 * @return If valid the identity is returned.
	 */
	public static @NotNull String validateAsListOfDigits(@NotNull @ValidListOfDigits String value) {
		return value;
	}
	
	/**
	 * Checks if the passed value is "true", "t", "yes", "y", "sure", "aye", "ja" or "1". If this is the case it is 
	 * accepted as a value for "true" and so true is returned else false.
	 * 
	 * @param value
	 * 		The value that should be checked.
	 * @return
	 * 		Boolean value if the passed String is 
	 */
	public static boolean checkBoolean(String value){
		boolean result = "true".equalsIgnoreCase(value) || "t".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)
		|| "y".equalsIgnoreCase(value) || "sure".equalsIgnoreCase(value) || "aye".equalsIgnoreCase(value)
		|| "ja".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value);
		return result;
	}
	
	/**
	 * This method prints the ids of objects that should be deleted before a specific object can be deleted.
	 * 
	 * @param ids
	 * 			Ids of the objects that should be deleted first.
	 * @param objectToDelete
	 * 			The type of the object that should be deleted. This is only given by a String.
	 * @param type
	 * 			The type of the object that use the object, so it should be deleted before. This is only given 
	 * 			by a String.
	 */
	public static void printIdsForDeletion(List<String> ids, String objectToDelete, String type){
			String message = "This " +objectToDelete + " is still used. Please delete first " +  type + " with id: ";
			message += String.join(",", ids);
			throw new ApiError(Response.Status.FORBIDDEN, message);