package ai.ilikeplaces.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by IntelliJ IDEA.
 * User: Ravindranath Akila
 * Date: Jan 1, 2010
 * Time: 4:29:55 PM
 */

// @License(content = "This code is licensed under GNU AFFERO GENERAL PUBLIC LICENSE Version 3")
final public class ReturnImpl<T> implements Return {

    final static private Logger logger = LoggerFactory.getLogger(ReturnImpl.class);

    final static private String logMsgBeginning = "SORRY! I ENCOUNTERED AN EXCEPTION! HOWEVER, THE APPLICATION SHOULD REMAIN INTACT. SEE BELOW FOR MORE DETAILS.\n\n";

    private int returnStatus = 1;

    private T returnValue = null;

    private Throwable returnError = null;

    private String returnMsg = null;

    public ReturnImpl(final int returnStatus, final T returnValue, final Throwable returnError, final String returnMsg) {
        this.returnStatus = returnStatus;
        this.returnValue = returnValue;
        this.returnError = returnError;
        this.returnMsg = returnMsg;
    }

    public ReturnImpl(final T returnValue, final String returnMsg) {
        this.returnStatus = 0;
        this.returnValue = returnValue;
        this.returnMsg = returnMsg;
//        if (log.length > 0 && (Boolean) log[0]) {
//            logger.info("HELLO, RETURN VALUES:{}",
//                    "ReturnImpl{" +
//                            "returnStatus=" + returnStatus +
//                            ", returnValue=" + returnValue != null ? returnValue.toString() : "null" +
//                            ", returnMsg='" + returnMsg + '\'' +
//                            '}');
//        }
    }

    public ReturnImpl(final Throwable returnError, final String returnMsg, final boolean shouldLog) {
        if (shouldLog) {
            logger.error(logMsgBeginning + returnMsg + "\n", returnError);
        }
        this.returnStatus = 1;
        this.returnError = returnError;
        this.returnMsg = returnMsg;
    }

    @Override
    final public int returnStatus() {
        return returnStatus;
    }

    @Override
    final public T returnValue() {
        return returnValue;
    }

    @Override
    final public Throwable returnError() {
        return returnError;
    }

    @Override
    public String returnMsg() {
        return returnMsg;
    }

    @Override
    public String toString() {
        return "Return{" +
                "returnStatus=" + returnStatus +
                ", returnValue=" + (returnValue != null ? returnValue.toString() : "null") +
                ", returnError=" + (returnError != null ? returnError.toString() : "null") +
                ", returnMsg='" + (returnMsg != null ? returnMsg : "") + '\'' +
                '}';
    }
}
@@ -1210,434 +1210,8 @@
 sg;%0A
-//        if (log.length %3E 0 && (Boolean) log%5B0%5D) %7B%0A//            logger.info(%22HELLO, RETURN VALUES:%7B%7D%22,%0A//                    %22ReturnImpl%7B%22 +%0A//                            %22returnStatus=%22 + returnStatus +%0A//                            %22, returnValue=%22 + returnValue != null ? returnValue.toString() : %22null%22 +%0A//                            %22, returnMsg='%22 + returnMsg + '%5C'' +%0A//                            '%7D');%0A//        %7D%0A
     
@@ -1352,22 +1352,33 @@
         
-l
+L
 ogger
+s.EXCEPTION
 .error(l

change logger and removed a commented code