/*
 * Copyright 2016 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 leap.web.api.mvc;

import leap.lang.http.HTTP;
import leap.lang.http.client.HttpHeaders;
import leap.lang.http.client.SimpleHttpHeaders;
import leap.lang.meta.annotation.TypeWrapper;
import leap.web.ResponseEntity;

@TypeWrapper
public class ApiResponse<T> implements ResponseEntity {

    //SUCCESS
    public static final ApiResponse OK         = of(HTTP.Status.OK,         null);
    public static final ApiResponse ACCEPTED   = of(HTTP.Status.ACCEPTED,   null);
    public static final ApiResponse NO_CONTENT = of(HTTP.Status.NO_CONTENT, null);

    //ERROR
    public static final ApiResponse NOT_FOUND       = err(HTTP.Status.NOT_FOUND,       "The resource does not exists.");
    public static final ApiResponse NOT_IMPLEMENTED = err(HTTP.Status.NOT_IMPLEMENTED, "Not implemented operation.");

    public static ApiResponse ok(Object entity) {
        return of(HTTP.Status.OK, entity);
    }

    public static ApiResponse created(Object entity) {
        return of(HTTP.Status.CREATED, entity);
    }

    public static ApiResponse badRequest(String message) {
        return err(HTTP.Status.BAD_REQUEST, "BadRequest", message);
    }

    public static ApiResponse err(HTTP.Status status, String message) {
        return of(status, new ApiError(status.name(), message));
    }

    public static ApiResponse err(HTTP.Status status,String errorCode, String message){
        return of(status,new ApiError(errorCode,message));
    }

    public static ApiResponse of(HTTP.Status status, Object entity) {
        return new ApiResponse(status, entity);
    }

    public static ApiResponse of(Object entity) {
        if(null == entity) {
            return NOT_FOUND;
        }else{
            return ok(entity);
        }
    }

    protected final HTTP.Status status;
    protected final Object      entity;
    protected final HttpHeaders headers = new SimpleHttpHeaders();

    protected ApiResponse(HTTP.Status status, Object entity) {
        this.status = status;
        this.entity = entity;
    }

    @Override
    public HTTP.Status getStatus() {
        return status;
    }

    @Override
    public HttpHeaders getHeaders() {
        return headers;
    }

    @Override
    public Object getEntity() {
        return entity;
    }

    /**
     * Sets the header.
     */
    public ApiResponse<T> setHeader(String name, String value) {
        headers.set(name, value);
        return this;
    }

    /**
     * Adds the header value.
     */
    public ApiResponse<T> addHeader(String name, String value) {
        headers.add(name, value);
        return this;
    }

}
@@ -1757,32 +1757,148 @@
 essage);%0A    %7D%0A%0A
+    public static ApiResponse notFound(String message) %7B%0A        return err(HTTP.Status.NOT_FOUND, message);%0A    %7D%0A%0A
     public stati

add 'notFound(String message)' in ApiResponse