package cn.common.enums;

import org.springframework.http.HttpStatus;

/**请求返回结果枚举*/
public enum ResultCode 
{
	/**<=500 系统错误 真正的报错*/
	//HTTP协议相关https://www.jianshu.com/p/2fca79fdad04
	HTTP_SUCCESS(200, "操作成功"),
    HTTP_ERROR_100(100, "1XX错误"),
    HTTP_ERROR_300(300, "3XX错误"),
    HTTP_ERROR_400(400, "4XX错误"),
    HTTP_ERROR_500(500, "5XX错误"),
    HTTP_BAD_REQUEST(400, "请求出现语法错误"),
    HTTP_UNAUTHORIZED(401, "无效的授权码"),
    HTTP_INVALID_CLIENTID(402, "无效的密钥"),
    HTTP_FORBIDDEN(403, "资源不可用"),
    HTTP_REQUEST_NOT_FOUND(404, "访问地址不存在"),
    HTTP_METHOD_NOT_ALLOWED(405, "不支持当前请求方法"),
    HTTP_REPEAT_REQUEST_NOT_ALLOWED(406, "请求重复提交"),
    HTTP_INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
	
    /**>1000 操作错误 不是系统错误*/
    
    JOB_STATUS(9001,"定时器状态更新异常"),
    JOB_RUN(9002,"定时器执行异常"),
    JOB_DELETE(9003,"定时器删除异常"),
    JOB_ADD(9004,"定时器新增异常"),
    JOB_UPDATE(9005,"定时器更新异常"),
    JOB_CRON(9006,"cron表达式不正确"),
    
    DATE_PARSE(8001,"日期转换异常"),
    TOKEN_EXPIRED(8002,"Token过期"),
    TOKEN_GENERTATION(8003,"生成Token失败"),
    ARRAY_EXCEPTION(8005, "数组异常"),
    ARRAY_OUT_OF_BOUNDS(8006, "数组越界异常"),
    JSON_SERIALIZE(8007, "序列化数据异常"),
    JSON_DESERIALIZE(8008, "反序列化数据异常"),
    EMAIL_SEND_EXCEPTION(8010, "邮件发送异常"),
    
    FILE_DOWNLOAD(7001, "下载文件异常"),
    FILE_UPLOAD(7002, "上传文件异常"),
    FILE_DELETE(7003, "文件删除异常"),
    FILE_READ(7004, "读文件异常"),
    FILE_WRITE(7005, "写文件异常"),
    FILE_NOEXIST(7006, "文件不存在"),
    FILE_OVARSIZE(7007, "文件大小超出限制"),    
    FILE_EXPORT(7008, "下载导出文件异常"),
    FILE_IMPORT(7009, "上传导入文件异常"),
    FILE_IO(7010, "IO异常"),
    FILE_JSON(7011, "JSON配置文件不存在"),
    
    //SQL语句
    SQL_RUN(6000, "运行时SQL报错"),
    SQL_SQL(6001, "SQL语句存在语法错"),
    SQL_DELETE(6002, "数据删除异常"),
    SQL_INSERT(6003, "数据插入异常"),
    SQL_UPDATE(6004, "数据更新异常"),
    SQL_CLEAR(6005,"数据库清空异常"),
	    
	//参数错误
	PARAM_ERR(5000,"参数错误"),
	PARAM_INVALID(5001,"参数无效"),
    PARAMS_BANK(5002,"参数为空"),
    PARAMS_TYPE(5003,"参数类型错误"),
    PARAMS_NOT_COMPLETE(5004,"参数缺失"),
       
	//接口异常
    API_EXCEPTION(4000, "接口异常"),
    API_NOT_FOUND(4001, "接口不存在"),
    API_REQ_MORE(4002, "接口访问过于频繁，请稍后再试"),
    API_IDEMPOTENT(4003, "接口不可以重复提交，请稍后再试"),
    API_PARAM(4004, "参数异常"),
    API_PARAM_MISSING(4005, "缺少参数"),
    API_METHOD_NOT_SUPPORTED(4006, "不支持的Method类型"),
    API_METHOD_PARAM_TYPE(4007, "参数类型不匹配"),
       
    //系统运行环境异常
    SYS_SERVER(3000, "服务器内部错误"),
    SYS_START(3001, "系统启动异常"),
    SYS_REDIS(3002, "redis异常"),
    SYS_REDIS_CONNECT(3003, "redis连接异常"),
    SYS_PROC(3004, "进程失败"),
    SYS_ENCODING(3015, "编码异常"),
    SYS_ENCODING_UNSUPPORTED(3016, "编码不支持异常"),
    SYS_RESOURSE_READ_EXCEPTION(3022, "读取资源异常"),
    SYS_RESOURSE_NOT_FOUND(3023, "资源不存在异常"),
    SYS_RUNTIME(3024, "运行时异常"),
    SYS_NULL_POINTER(3025, "空指针异常"),
    SYS_CLASS_CAST(3026, "类型转换异常"),  
    
 	//用户相关段
    USER_NO_AUTHZ(2000, "访问权限认证未通过"),
	USER_NOT_LOGIN(2001, "用户未登录"),
    USER_ACCOUNT_EXPIRED(2002, "账号已过期"),
    USER_CREDENTIALS_ERROR(2003, "密码错误"),
    USER_CREDENTIALS_EXPIRED(2004, "密码过期"),
    USER_ACCOUNT_DISABLE(2005, "账号不可用"),
    USER_ACCOUNT_LOCKED(2006, "账号被锁定"),
    USER_ACCOUNT_NOT_EXIST(2007, "账号不存在"),
    USER_ACCOUNT_EXIST(2008, "账号已存在"),
    USER_ACCOUNT_OFFLIN(2009, "账号下线"),
    USER_TIME_OUT(2012, "访问超时"),
    USER_KICK_OUT(2013, "您已经在其他地方登录，请重新登录！"),
    USER_BIND_PHONE(2014, "请绑定手机号"),
    USER_NAME_PWD(2015, "用户名或密码为空"),
    USER_LOGINED_IN(2016, "该用户已登录"),
    USER_UNAUTHORIZED(2017, "操作未授权"),
    USER_EMAIL_EXIST(2018,"邮箱已经存在"),
    USER_PHONE_EXIST(2019,"电话号码已经存在"),
    USER_SIGN_VERIFI_NOT_COMPLIANT(2020,"签名校验不合规"),
    USER_PASSWORD_RESET_FAILED(2021, "重置密码失败"),
    USER_UNKONWN_INDENTITY(2022, "未知身份"),
    USER_FIRST_LANDING(2023, "首次登录"),
    USER_NOT_LOGGED_IN(2024,"用户未登录，访问路径需要验证"),
    USER_NOT_LOGIN_ERROR(2025,"用户不存在或密码错误"),
    USER_MANY_LOGINS(2026,"多用户在线"),
    USER_TOO_MANY_PASSWD(2027, "密码输入次数过多"),
    USER_VERIFICATION_CODE_INCORECT(2028,"图形验证码不正确"),
    USER_VERIFICATION_CODE_FAIL(2029,"图形验证码生产失败"),
    USER_NAME_EXIST(2030,"登录账号已存在"),
    
	//数据错误
    DATA_EXCEPTION(1000, "数据异常"),
	DATA_EXIST(1001, "数据已经存在"),
	DATA_AP_USER_NOT_EXIST(1002, "用户数据不存在"),
	DATA_NOT_EXIST(1003, "未找到符合条件的数据异常"),
	DATA_TOO_LENGTH(1004, "字段太长,超出数据库字段的长度"),
	DATA_CALCULATION(1005, "数据计算异常"),
	DATA_COMPRESS(1006, "数据压缩异常"),
	DATA_DE_COMPRESS(1007, "数据解压缩异常"),
	DATA_CONVERT(1009, "数据转换异常"),
	DATA_NOEXIST(1010, "数据不存在"),
	DATA_PARSE(1099, "数据解析异常");
	
	private Integer code;
	private String msg;
	ResultCode(Integer code) {
		this.code = code;
	}
	ResultCode(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	public Integer getCode() {
		return code;
	}
	public String getMsg() {
		return msg;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public void setMsg(String message) {
		this.msg = message;
	}

	/** 返回的HTTP状态码,  符合http请求 */
	private HttpStatus httpStatus;

	ResultCode(HttpStatus httpStatus, Integer code, String msg) {
		this.httpStatus = httpStatus;
		this.code = code;
		this.msg = msg;
	}

	public HttpStatus getHttpStatus() {
		return httpStatus;
	}

	public void setHttpStatus(HttpStatus httpStatus) {
		this.httpStatus = httpStatus;
	}
	public static String getMsgByCode(Integer code) {
		for (ResultCode ele : values()) {
			if (ele.getCode().equals(code)) {
				return ele.getMsg();
			}
		}
		return null;
	}   
}

