package me.freezehome.blog.model;

import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import me.freezehome.blog.status.enums.ReturnStatus;

/**
 * Created by freeze on 17-1-25.
 */
public class ViewModel extends ObjectNode {

    private static ViewModel okModel = new ViewModel();

    static {
        okModel.put("info", "ok");
    }

    private static ViewModel getOkModel(){
        if ( okModel == null ){
            okModel = new ViewModel();
            okModel.put("info", "ok");
        }
        return okModel;
    }

    private ViewModel(){
        super(JsonNodeFactory.instance);
    }

    public ViewModel(ReturnStatus returnStatus, ObjectNode o) {
        super(JsonNodeFactory.instance);
        String status = "status";
        String data = "detail";
        this.put(status, returnStatus.getStatus());
        this.set(data, o);
    }

    public static ViewModel ok(){
       return getOkModel();
    }
}
