package com.pm.server.utils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.pm.server.datatype.Coordinate;
import com.pm.server.datatype.PlayerState;
import com.pm.server.exceptionhttp.BadRequestException;
import com.pm.server.request.PlayerStateRequest;

public class ValidationUtils {

	private final static Logger log =
			LogManager.getLogger(ValidationUtils.class.getName());

	public static void validateRequestBodyWithLocation(Coordinate location)
			throws BadRequestException {

		String errorMessage = null;

		if(location == null) {
			errorMessage = "Request body requires latitude and longitude.";
		}
		else if(
				location.getLatitude() == null &&
				location.getLongitude() == null) {
			errorMessage = "Request body requires latitude and longitude.";
		}
		else if(location.getLatitude() == null) {
			errorMessage = "Request body requires latitude.";
		}
		else if(location.getLongitude() == null) {
			errorMessage = "Request body requires longitude.";
		}

		if(errorMessage != null) {
			log.warn(errorMessage);
			throw new BadRequestException(errorMessage);
		}

	}

	public static PlayerState validateRequestBodyWithState(
			PlayerStateRequest stateRequest)
			throws BadRequestException {

		if(stateRequest == null) {
			String errorMessage = "Request body requires a state.";
			log.warn(errorMessage);
			throw new BadRequestException(errorMessage);
		}

		PlayerState state = null;
		try {
			state = PlayerState.valueOf(stateRequest.state);
		}
		catch(IllegalArgumentException e) {
			log.warn(e.getMessage());

			String errorMessage = "Request body requires a valid state.";
			log.warn(errorMessage);
			throw new BadRequestException(errorMessage);
		}

		return state;

	}

}

@@ -1423,24 +1423,202 @@
 essage);%0A%09%09%7D
+%0A%09%09else if(stateRequest.state == null) %7B%0A%09%09%09String errorMessage = %22Request body requires a state.%22;%0A%09%09%09log.warn(errorMessage);%0A%09%09%09throw new BadRequestException(errorMessage);%0A%09%09%7D
 %0A%0A%09%09PlayerSt

Add extra check for validated stateRequest