package com.hmsoft.remote.rmi.model;

/**
 * 
 * Response
 *
 */
public class Response {
    public static final String HEARTBEAT_EVENT = null;
    public static final String READONLY_EVENT = "R";
	public static final byte OK = 20;
	public static final byte CLIENT_TIMEOUT = 30;
	public static final byte SERVER_TIMEOUT = 31;
	public static final byte BAD_REQUEST = 40;
	public static final byte BAD_RESPONSE = 50;
    public static final byte SERVER_ERROR = 60;
	public static final byte CLIENT_ERROR = 90;
	public static final byte SERVICE_ERROR = 100;//业务错误
    private long mId = 0;
    private byte mStatus = OK;
    private String mErrMsg;
    private boolean mEvent = false;
    private Object mResult;
    private String mVersion;
    
    public Response(){
    }

    public Response(long id){
        mId = id;
    }
    
    public Response(long id, String version) {
        mId = id;
        mVersion = version;
    }
    
    public boolean isEvent() {
        return mEvent;
    }

    public void setEvent(String event) {
        mEvent = true;
        mResult = event;
    }

    public boolean isHeartbeat() {
        return mEvent && HEARTBEAT_EVENT == mResult;
    }
    
    public long getId() {
		return mId;
	}

	public void setId(long mId) {
		this.mId = mId;
	}

	public byte getStatus() {
		return mStatus;
	}

	public void setStatus(byte mStatus) {
		this.mStatus = mStatus;
	}

	public String getErrMsg() {
		return mErrMsg;
	}

	public void setErrMsg(String mErrMsg) {
		this.mErrMsg = mErrMsg;
	}

	public Object getResult() {
		return mResult;
	}

	public void setResult(Object mResult) {
		this.mResult = mResult;
	}
	
    public String getVersion() {
        return mVersion;
    }

    public void setVersion(String version) {
        mVersion = version;
    }

    @Override
    public String toString() {
        return "Response [id=" + mId + ", version=" + mVersion + ", status=" + mStatus + ", event=" + mEvent
                + ", error=" + mErrMsg + ", result=" + (mResult == this ? "this" : mResult) + "]";
    }
}
