package com.unissoft.model;

import java.io.Serializable;

//返回基类
public class ResponseEntity<T> implements Serializable {

    private static final long serialVersionUID = -2825436079063723409L;

    //成功
    private static final String OK = "200";
    //失败
    private static final String FAILED = "600";
    private static final String BUSSINESS_FAILED = "550";
    private static final String UNAUTHENTICATION = "401";

    private String retCode;
    private String message;
    private T data;

    public String getRetCode() {
        return retCode;
    }

    public void setRetCode(String retCode) {
        this.retCode = retCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private static <T> ResponseEntity<T> buildResponse(String retCode, String message, T data){
        ResponseEntity<T> responseEntity = new ResponseEntity<T>();
        responseEntity.retCode = retCode;
        responseEntity.message = message;
        responseEntity.data = data;
        return responseEntity;
    }

    public static <T> ResponseEntity<T> ok(){
        return buildResponse(ResponseEntity.OK,"success",null);
    }
    public static <T> ResponseEntity<T> ok(T data){
        return buildResponse(ResponseEntity.OK,"success",data);

    }
    public static <T> ResponseEntity<T> ok(String message, T data){
        return buildResponse(ResponseEntity.OK,message,data);
    }


    public static <T> ResponseEntity<T> failed(String message){
        return buildResponse(ResponseEntity.FAILED,message,null);
    }

    public static <T> ResponseEntity<T> businessFailed(String message){
        return buildResponse(ResponseEntity.BUSSINESS_FAILED,message,null);
    }

    public static <T> ResponseEntity<T> unauthentication(String message){
        return buildResponse(ResponseEntity.UNAUTHENTICATION,message,null);
    }

    private String state;
    private String msg;

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}

