package com.energy.manage.common.reponse;

import com.alibaba.fastjson.JSONObject;
import org.springframework.util.StringUtils;

public class RespMsg {

  /**
   * 操作成功
   */
  public static JSONObject SUCCESS() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.SUCCESS.getCode());
    RS.put("msg", ConstVar.SUCCESS.getMsg());
    RS.put("status", true);
    return RS;
  }

  /**
   * 操作成功
   */
  public static JSONObject SUCCESS(int code, String msg, Object data) {
    JSONObject RS = new JSONObject();
    RS.put("code", code);
    RS.put("msg", msg);
    RS.put("data", data);
    RS.put("status", true);
    return RS;
  }

  public static JSONObject SUCCESS(Object data) {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.SUCCESS.getCode());
    RS.put("msg", ConstVar.SUCCESS.getMsg());
    RS.put("data", data);
    RS.put("status", true);
    return RS;
  }

  /**
   * 操作失败
   */
  public static JSONObject FAIL() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.FAIL.getCode());
    RS.put("msg", ConstVar.FAIL.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 上传操作超时
   */
  public static JSONObject TIMEOUT() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.TIMEOUT.getCode());
    RS.put("msg", ConstVar.TIMEOUT.getMsg());
    RS.put("status", false);
    return RS;
  }

  public static JSONObject FAIL(Integer code, String msg) {
    JSONObject RS = new JSONObject();
    RS.put("code", code);
    RS.put("msg", msg);
    RS.put("status", false);
    return RS;
  }

  public static JSONObject FAIL(String msg) {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.FAIL.getCode());
    RS.put("msg", msg);
    RS.put("status", false);
    return RS;
  }


  /**
   * 参数不能为空
   *
   * @return
   */
  public static JSONObject NOTNULLPARAM() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.NOTNULLPARAM.getCode());
    RS.put("msg", ConstVar.NOTNULLPARAM.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 用户已存在
   *
   * @return
   */
  public static JSONObject EXISTSUSER() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.EXISTSUSER.getCode());
    RS.put("msg", ConstVar.EXISTSUSER.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 账号被停用
   *
   * @return
   */
  public static JSONObject EXISTSUSERNOTUSE() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.EXISTSUSERNOTUSE.getCode());
    RS.put("msg", ConstVar.EXISTSUSERNOTUSE.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 用户不存在
   *
   * @return
   */
  public static JSONObject NOTEXISTSUSER() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.NOTEXISTSUSER.getCode());
    RS.put("msg", ConstVar.NOTEXISTSUSER.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 密码错误
   *
   * @return
   */
  public static JSONObject ERRORPWD() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.ERRORPWD.getCode());
    RS.put("msg", ConstVar.ERRORPWD.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 无效参数
   *
   * @return
   */
  public static JSONObject INVALIDPARAM(String param) {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.INVALIDPARAM.getCode());
    RS.put("msg", ConstVar.INVALIDPARAM.getMsg() + "-" + param);
    RS.put("status", false);
    return RS;
  }


  /**
   * 请登录用户
   *
   * @return
   */
  public static JSONObject PLEASELOGIN() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.PLEASELOGIN.getCode());
    RS.put("msg", ConstVar.PLEASELOGIN.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * token失效
   *
   * @return
   */
  public static JSONObject TOKENVALID() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.TOKENINVALID.getCode());
    RS.put("msg", ConstVar.TOKENINVALID.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 验签失败
   *
   * @return
   */
  public static JSONObject ERRORSIGN() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.ERRORSIGN.getCode());
    RS.put("msg", ConstVar.ERRORSIGN.getMsg());
    RS.put("status", false);
    return RS;
  }

  public static JSONObject SMSOVERDUE() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.SMSOVERDUE.getCode());
    RS.put("msg", ConstVar.SMSOVERDUE.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 验证码错误
   *
   * @return
   */
  public static JSONObject SMSFAIL() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.SMSFAIL.getCode());
    RS.put("msg", ConstVar.SMSFAIL.getMsg());
    RS.put("status", false);
    RS.put("data", null);
    return RS;
  }

  /**
   * 验证码错误
   *
   * @return
   */
  public static JSONObject EQUIOMENGTINUSE() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.EQUIOMENGTINUSE.getCode());
    RS.put("msg", ConstVar.EQUIOMENGTINUSE.getMsg());
    RS.put("status", false);
    RS.put("data", null);
    return RS;
  }

  /**
   * 微信授权失败
   *
   * @return
   */
  public static JSONObject WEIXINEXCEPTIONSMSOVERDUE() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.WEIXIN_EXCEPTION_SMSOVERDUE.getCode());
    RS.put("msg", ConstVar.WEIXIN_EXCEPTION_SMSOVERDUE.getMsg());
    RS.put("status", false);
    RS.put("data", null);
    return RS;
  }

  public static JSONObject FAILException() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.FAIL.getCode());
    RS.put("status", false);
    RS.put("msg", "系统错误，请联系管理员");
    return RS;
  }

  /**
   * 验证码发送太频繁
   *
   * @return
   */
  public static JSONObject SMSCODEFREQUENT() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.SMSCODEFREQUENT.getCode());
    RS.put("msg", ConstVar.SMSCODEFREQUENT.getMsg());
    RS.put("data", null);
    return RS;
  }

  public static JSONObject ISDONE(String msg) {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.ISDONE.getCode());
    RS.put("msg", msg);
    RS.put("status", false);
    return RS;
  }

  /**
   * 微信验证码发送太频繁
   *
   * @return
   */
  public static JSONObject WXUSERCODE(String appid) {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.WEIXIN_EXCEPTION_CODE.getCode());
    RS.put("msg", ConstVar.WEIXIN_EXCEPTION_CODE.getMsg());
    RS.put("data", appid);
    return RS;
  }

  /**
   * 两次密码输入不一致，请重新确认
   *
   * @return
   */
  public static JSONObject CONSISTENCYNOTPWD() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.CONSISTENCY_NOT_PWD.getCode());
    RS.put("msg", ConstVar.CONSISTENCY_NOT_PWD.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 用户未登录
   *
   * @param msg
   * @return
   */
  public static JSONObject NOTLOGIN(String msg) {
    if (StringUtils.isEmpty(msg)) {
      return buildRespMsg(ConstVar.NOTLOGIN.getCode(), ConstVar.NOTLOGIN.getMsg(), null);
    }
    return buildRespMsg(ConstVar.NOTLOGIN.getCode(), msg, null);
  }

  /**
   * 用户已掉线
   *
   * @param msg
   * @return
   */
  public static JSONObject INVALIDATETOKEN(String msg) {
    if (StringUtils.isEmpty(msg)) {
      return buildRespMsg(ConstVar.INVALIDATE_TOKEN.getCode(), ConstVar.INVALIDATE_TOKEN.getMsg(), null);
    }
    return buildRespMsg(ConstVar.INVALIDATE_TOKEN.getCode(), msg, null);
  }


  /**
   * 重复提交
   *
   * @return
   */
  public static JSONObject NOREQUEST() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.NOREQUEST_CODE.getCode());
    RS.put("msg", ConstVar.NOREQUEST_CODE.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * 系列课不存在
   *
   * @return
   */
  public static JSONObject NOTEXISTCOURSESERIES() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.NOT_EXIST_COURSE_SERIES.getCode());
    RS.put("msg", ConstVar.NOT_EXIST_COURSE_SERIES.getMsg());
    RS.put("status", false);

    return RS;
  }

  /**
   * 课程不存在
   *
   * @return
   */
  public static JSONObject NOTEXISTCOURSE() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.NOT_EXIST_COURSE.getCode());
    RS.put("msg", ConstVar.NOT_EXIST_COURSE.getMsg());
    RS.put("status", false);
    return RS;
  }

  /**
   * id为空
   *
   * @return
   */
  public static JSONObject PARAM_ID_NULL() {
    JSONObject RS = new JSONObject();
    RS.put("code", ConstVar.PARAM_ID_NULL.getCode());
    RS.put("msg", ConstVar.PARAM_ID_NULL.getMsg());
    RS.put("status", false);
    return RS;
  }


  /**
   * 内部方法，构建返回值实体对象
   *
   * @param code
   * @param msg
   * @param data
   * @return
   */
  private static JSONObject buildRespMsg(Integer code, String msg, Object data) {
    JSONObject RS = new JSONObject();
    if (null != code) {
      RS.put("code", code);
    }
    if (!StringUtils.isEmpty(msg)) {
      RS.put("msg", msg);
    }
    if (null != data) {
      RS.put("data", data);
    }
    return RS;
  }


}
