package com.shinsoft.sto.model.system;

/**
 * 响应码和消息常量
 */
public class ResponseCodeMsg {
    
    // 成功状态码和消息 - 与 JSONTools.java 保持一致
    public static final String CODE_SUCCESS = "0";
    public static final String MSG_OK = "操作成功";
    
    // 异常状态码和消息
    public static final String CODE_EX = "500";
    public static final String MSG_EX = "系统异常";
    
    public static final String CODE_NULL = "400";
    public static final String MSG_NULL = "参数为空";
    
    // 其他常用状态码
    public static final String CODE_FAIL = "-1";
    public static final String MSG_FAIL = "操作失败";
    
    public static final String CODE_VALIDATE_ERROR = "401";
    public static final String MSG_VALIDATE_ERROR = "参数校验失败";
    
    public static final String CODE_UNAUTHORIZED = "403";
    public static final String MSG_UNAUTHORIZED = "未授权";
    
    public static final String CODE_NOT_FOUND = "404";
    public static final String MSG_NOT_FOUND = "资源不存在";
    
    // 私有构造方法，防止实例化
    private ResponseCodeMsg() {
    }
    
    /**
     * 根据状态码获取对应的消息
     */
    public static String getMessageByCode(String code) {
        switch (code) {
            case CODE_SUCCESS:
                return MSG_OK;
            case CODE_EX:
                return MSG_EX;
            case CODE_NULL:
                return MSG_NULL;
            case CODE_FAIL:
                return MSG_FAIL;
            case CODE_VALIDATE_ERROR:
                return MSG_VALIDATE_ERROR;
            case CODE_UNAUTHORIZED:
                return MSG_UNAUTHORIZED;
            case CODE_NOT_FOUND:
                return MSG_NOT_FOUND;
            default:
                return "未知状态码";
        }
    }
    
    /**
     * 判断状态码是否表示成功
     */
    public static boolean isSuccess(String code) {
        return CODE_SUCCESS.equals(code);
    }
    
    /**
     * 判断状态码是否表示失败
     */
    public static boolean isFail(String code) {
        return !isSuccess(code);
    }
}