package com.iformall.common;

import java.text.MessageFormat;

/**
 * @author chenkx
 * @date 2017-12-28.
 */
public enum ErrorCode{

    /**
     * 系统级别
     * 1000-1999
     */
    SYS_SERVER_ERROR(1000, "服务器请求异常"),
    SYS_PARAMETER_ERROR(1001, "参数不合法"),
    SYS_PARAMETER_NOT_NULL(1002, "参数不能为空"),
    SYS_PARAMETER_TYPE_ERROR(1003, "参数类型异常"),
    SYS_PARAMETER_CAST_ERROR(1004, "参数转换异常"),
    SYS_PARAMETER_EMPTY_ERROR(1005, "参数转换异常"),
    SYS_BEAN_EMPTY_PROPERTY_ERROR(1006, "实体转换异常"),
    SYS_MEDIATYPE_NOT_SUPPORT(1007, "不支持的媒体类型"),
    SYS_NULLPOINTER_ERROR(1008, "空指针异常"),
    SYS_METHOD_NOT_SUPPORT(1009, "不支持的请求类型"),
    SYS_CLASSCAST_ERROR(1010, "类型转换异常"),
    SYS_NUMBER_FORMAT_ERROR(1011, "数字转化异常"),
    SYS_EXTEND_JSON_ERROR(1012, "JSON格式异常"),
    SYS_REPEAT_SUBMIT_EXCEPTION(1013, "请勿重复操作"),

    /**
     * 数据库
     */
    DB_FAIL(1045, "数据库访问出错"),

    /**
     * 网络
     */
    TOO_MANY_REQUEST(1050, "太多的请求访问"),

    LOGIN_DENIED(1051, "登录失败"),
    NET_TOKEN_INVALID(1052, "TOKEN无效"),
    NET_TOKEN_EMPTY(1053, "TOKEN不能为空"),


    /**
     * 业务级别
     */
    /**
     * 用户2000-2099
     */
    USER_PASSWD_ERR(1987, "用户名或者密码错误"),
    USER_IS_MULTI(1988, "有多个手机号，请联系富茂管理员"),
    USER_IS_NOT_MEMBER(1989,"用户还未授权手机号成为会员"),
    USER_PHONE_IS_NOT_FOUND(1990,"手机号不存在"),
    USER_DEL_SELF(1991,"用户删除自己"),
    USER_NOT_ADMIN(1992,"用户非超管"),
    USER_NO_PERMISSION(1993,"用户无此权限"),
    USER_USE_ROLE(1994,"用户使用此角色"),
    USER_IS_EMPTY(2000, "用户不存在"),
    PASSWORD_ERROR(2001, "密码错误"),
    USER_IS_LOCKED(2003, "用户已经被禁用不能登录，请与管理员联系"),
    NEW_USER_FAILD(2004, "创建新用户失败"),
    BUSER_NOT_IN_APP(2005, "用户不是此app用户"),
    KAPCHA_NOT_VALID(2006, "验证码已失效"),
    KAPCHA_NOT_EQUAL(2007, "验证码不正确"),
    USER_NAME_IS_FOUND(2008,"用户名已存在"),
    USER_PHONE_IS_FOUND(2009,"手机号已存在"),


    /**
     * 商场/商户
     */
    MALL_INFO_NOT_FOUND(2010, "商场信息没找到"),
    MERCHANT_INFO_NOT_FOUND(2011, "商户信息没找到"),
    MERCHANT_INFO_NOT_EQUAL(2012, "商户信息不对应"),
    MERCHANT_INFO_NOT_VALID(2013, "商户信息禁用"),


    /**
     * 券
     */
    COUPON_IS_EMPTY(2020, "此券不存在"),
    COUPON_IS_NOT_FREE(2021, "此券不免费"),
    COUPON_IS_TAKE_OFF(2022, "此券已作废"),
    COUPON_IS_EXPIRED(2023, "此券已过期"),
    COUPON_IS_SELL_OUT(2024, "此券已售罄"),

    COUPON_TYPE_IS_NOT_ACTIVE(2025, "此券不能用于主动领取"),
    COUPON_TYPE_IS_NOT_PASSIVE(2026, "此券不能用于定向投放"),
    COUPON_CHANNEL_IS_EXISTED(2027, "此券已投放过"),
    COUPON_SEND_IS_EXISTED(2028, "此券已经添加到该渠道"),
    COUPON_SEND_IS_INVALID(2029, "此发券渠道不存在"),
    COUPON_SEND_IS_INVALID_TIME(2030, "投放的时间超出劵的有效期"),
    COUPON_CHANNEL_IS_TAKE_OFF(2031, "此券已下架"),
    COUPON_MERCHANT_NOT_FOUND(2032, "卡券关联商户未发现"),
    COUPON_CHANNEL_IS_NOT_STARTED(2033, "此券活动未开始"),
    COUPON_CHANNEL_IS_END(2033, "此券活动已结束"),

    PUSH_LIMIT_UP_TO_1DAYLIMIT(2040, "此用户一天内发券到达疲劳度限制"),
    PUSH_LIMIT_UP_TO_COUPONLIMIT(2041, "此用户发此券到达疲劳度限制"),
    PUSH_LIMIT_NOT_INRANG(2042, "不在疲劳度允许的时间段"),
    /**
     * 车流 2040
     */
    CAR_PARK_NOT_FOUND(2049, "车场未找到"),
    CAR_VENDOR_NOT_SUPPORT(2050, "不支持的停车厂家"),

    ETCP_LOGIN_FAIL(2051, "ETCP共同登录失败"),
    ETCP_BIND_FAIL(2052, "ETCP绑车牌失败"),
    ETCP_UNBIND_FAIL(2053, "ETCP解绑车牌失败"),
    ETCP_STOP_FEE_FAIL(2054, "ETCP停车费失败"),
    ETCP_QUAN_TEMP_FAIL(2055, "ETCP优免券模板失败"),
    ETCP_QUAN_SEND_FAIL(2056, "ETCP优免券发放失败"),
    ETCP_CMD_FAIL(2057, "ETCP网络异常"),

    TJD_BIND_FAIL(2060,"TJD绑车牌失败"),
    TJD_UNBIND_FAIL(2061,"TJD解绑车牌失败"),
    TJD_STOP_FEE_FAIL(2062, "TJD停车费失败"),
    TJD_DEDUCE_FEE_FAIL(2063, "TJD停车费抵扣失败"),

    /**
     * 游戏
     */
    GAME_NOT_FOUND(2070, "游戏未找到"),

    /**
     * 订单
     */
    REMAIN_IS_EMPTY(3000, "库存不足"),
    ORDER_IS_LIMITED(3001, "购买超限"),
    ORDER_IS_FAIL(3002, "订单失败"),
    ORDER_IS_NOT_FIND(3003, "订单不存在"),
    ORDER_IS_NOT_PAY(3004, "订单已不能进行支付"),
    ORDER_SAVE_ERR(3005,"订单保存失败"),
    ORDER_UPDATE_ERR(3006,"订单更新失败"),
    REMAIN_BACK_FAIL(3007, "库存恢复失败"),
    ORDER_HAD_PAY(3008, "订单已支付"),
    ORDER_HAD_CANCEL(3009, "订单已取消"),
    ORDER_PRESS_IS_OVERTIME(3010, "砍价已过期"),
    ORDER_PRESS_IS_COMPLETE(3011, "砍价已完成"),

    /**
     * 卡券
     */
    COUPON_ORDER_SAVE_ERR(3999, "卡券保存失败"),
    COUPON_ORDER_IS_NULL(4000, "卡券不存在"),
    COUPON_ORDER_IS_USED(4001, "卡券已核销"),
    COUPON_ORDER_IS_OVER_TIME(4002, "卡券已过期"),
    COUPON_ORDER_IS_INVALID(4003, "卡券已经作废"),
    COUPON_ORDER_BUSER_IS_NULL(4004, "卡券B端用户不存在"),
    COUPON_ORDER_MERANT_IS_NULL(4005, "卡券商户不存在"),
    COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE(4006, "卡券使用期还未开始"),
    COUPON_ORDER_IS_LATER_THAN_VALIDDATE(4007, "卡券使用期已结束"),

    /**
     * 卡
     */
    CARD_IS_NOT_FOUND(9001, "优惠卡不存在"),
    CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH(9002, "优惠卡余额不足"),
    CARD_IS_NOT_COST(9003, "优惠卡未消费，退款请用卡券退款，钱直接退回购买人手里"),
    CARD_TRANSFERED(9004, "卡已被领取"),
    CARD_TRANSFER_INVALID(9005, "卡转赠已失效"),

    /**
     * 卡消费
     */
    CARD_SPEND_IS_PAID(9050, "卡消费已支付"),

    /**
     * 砍价
     */
    COUPON_PRESS_HAD_FINISHED(9070, "砍价已完成"),
    COUPON_PRESS_IS_OVERTIME(9071, "砍价已超时"),
    COUPON_PRESS_IS_EXIST(9072, "此人已参与此次砍价"),




    /**
     * 微信
     */
    SESSION_KEY_DECODE_ERR(11001, "session_key/openId解密失败"),
    NICK_NAME_DECODE_ERR(11002, "nickName,unionId解密失败"),
    PHONE_DECODE_ERR(11003, "Phone解密失败"),
    NICK_NAME_NOT_FOUND(11004, "nickName,unionId未授权"),
    PHONE_NOT_FOUND(11005, "Phone未授权"),
    PHONE_IS_ENCRYPTED(11006, "Phone已加密"),
    TEMPLATE_SEND_FAILED(11007, "模板消息发送失败"),
    WE_RUN_DATA_DECODE_ERR(11008, "运动信息解密失败"),


    /**
     * 支付
     */
    PAY_ORDER_REFUND(11994, "订单退款中"),
    PAY_ORDER_PAYING(11995, "订单支付中"),
    PAY_ORDER_NOT_PAY(11996, "订单未支付"),
    PAY_ORDER_CLOSED(11997, "订单已关闭"),
    PAY_ORDER_REVERSE(11998, "订单已撤销"),
    PAY_ORDER_NOT_FOUND(12000, "支付订单不存在"),
    PAY_ORDER_EXIST(12001, "支付订单已存在"),
    PAY_ORDER_ERROR(12002, "支付订单异常"),
    PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR(12003 , "支付验签失败"),
    PAY_ORDER_IS_ZERO(12004, "支付订单金额为0"),
    PAY_ORDER_IS_NOT_PAYMENT(12005, "不是支付订单"),
    PREPAY_ID_IS_EMPTY(12006, "prepay_id是空值"),
    PAY_ORDER_QUERY_ERROR(12007, "支付订单查询异常"),

    REFUND_ORDER_EXIST(12010, "退款订单已存在"),
    REFUND_PAY_ORDER_IS_NOT_EXIST(12011, "退款支付订单不存在"),
    REFUND_PAY_ORDER_IS_ZERO(12012, "退款支付订单金额为0"),
    REFUND_ORDER_ERROR(12013, "退款订单异常"),
    REFUND_ORDER_NOTIFY_CHECK_SIGN_ERROR(12014, "退款验签失败"),
    REFUND_ORDER_BUSER_IS_NULL(12015, "B端用户不存在"),
    REFUND_ORDER_BUSER_NOT_EQUAL(12016, "B端用户无操作权限"),

    APP_ID_NOT_FOUND(12020, "APPID没找到"),
    MCH_INFO_NOT_FOUND(12021, "微信商户平台信息没找到"),
    MCH_INFO_NOT_EQUAL(12022, "微信商户平台信息不对应"),
    API_KEY_NOT_FOUND(12023, "支付密钥未配置"),
    CERT_PATH_NOT_FOUND(12024, "双向证书未配置"),

    PROFIT_SHARING_REQUEST_FAILED(12030, "分账请求失败"),
    PROFIT_SHARING_APPLY_FAILED(12031, "分账业务失败"),
    PROFIT_SHARING_RETURN_INVALID(12032, "分账请求返回校验失败"),
    PROFIT_SHARING_RECEIVER_INVALID(12033, "分账接受方查寻无效"),
    PROFIT_SHARING_QUERY_REQUEST_FAILED(12034, "分账查询请求失败"),
    PROFIT_SHARING_QUERY_APPLY_FAILED(12035, "分账查询业务失败"),
    PROFIT_SHARING_QUERY_RETURN_INVALID(12036, "分账查询返回校验失败"),
    PROFIT_SHARING_RECEIVER_ADD_FAILED(12037, "分账账户添加失败"),
    PROFIT_SHARING_RECEIVER_DEL_FAILED(12038, "分账账户删除失败"),
    PROFIT_SHARING_NUM_UP_LIMIT(12039, "分账次数超限"),
    /**
     * 核销
     */
    VERIFY_ERROR(12050, "核销异常"),
    MSG_REPEAT_SEND(12061, "短信重新发送"),

    /**
     * 解单
     */
    DALIY_REPORT_VOLUME_TODAY_NULL(12070, "今日解单不存在"),
    DALIY_REPORT_VOLUME_WEEK_NULL(12071, "无解单数据"),

    /**
     * 模板消息
     */
    TEMPLATE_NOT_FOUND(12090, "模板不存在"),

    /**
     *
     * 短信
     *
     * */
    MSG_SERVER_NOT_FIND(12100,"您还未接入短信运营商，请联系平台管理员"),
    MSG_TEMPLATE_REPEAT(12101,"您添加的短信模板已存在"),
    MSG_SIGNATURE_CONTENT_ERROR(12102,"短信签名或内容错误"),
    MSG_TEMPLATE_CREATE_ERROR(12103,"创建模板失败"),
    MSG_VERIFY_CODE_NOT_FOUND(12104,"短信验证码不存在或失效"),
    MSG_TEMPLATE_NOT_FOUND(12105,"短信模板不存在"),
    MSG_REQUEST_PARAMS_ERROR(12106,"参数错误"),
    MSG_SEND_ERROR(12107,"发送短信失败"),
    MSG_METHOD_REQUEST_ERROR(12108,"接口请求错误"),
    MSG_PHONE_NOT_FOUND(12109,"请输入手机号"),
    MSG_SEND_WAY_CHOOSE_ERROR(12110,"请确定发送的方式"),
    MSG_SUM_ZERO(12111,"短信数量为0"),
    MSG_SUM_INSUFFICENT(12112,"短信数量不足"),
    MSG_NO_VALID_PHONE(12113,"没有可以发送的手机号"),
    MSG_SEND_INTERFACE_ERROR(12114,"短信运营商返回错误"),
    /**
     * 会员
     */
    MEM_IMPORT_ERR(13000, "模板导入失败,请检查数据,尝试重新导入"),
    MEM_SCORE_NOT_ENOUGH(13001, "成长值不够扣减值"),

    /**
     * 标签
     */
    TAGS_MATCHED_NULL(14000, "此标签没命中用户"),


    /**
     * 租赁合同
     * */
    RENT_CONTRACT_IS_NOT_FOUND(15000,"租赁合同不存在"),
    RENT_CONTRACT_IS_TERMINATED(15001,"租赁合同已终止"),
    RENT_CONTRACT_WITH_SHOP_IS_FOUND(15002,"店铺存在已关联的合同"),
    /**
     * 物业合同
     * */
    PROPERTY_CONTRACT_IS_NOT_FOUND(16000,"物业合同不存在"),

    /**
     * 租赁账单
     * */
    BILL_RENT_IS_NOT_FOUND(17000,"租赁账单不存在"),

    /**
     * 租赁押金账单
     * */

    BILL_RENT_DEPOSIT_IS_NOT_FOUND(18000,"租赁押金账单不存在"),

    /**
     * 物业账单
     * */

    BILL_PROPERTY_IS_NOT_FOUND(19000,"物业账单不存在"),


    /**
     * 押金账单
     * */
    BILL_PROPERTY_DEPOSIT_IS_NOT_FOUND(20000,"物业押金账单不存在"),
    BILL_OTHER_DEPOSIT_IS_NOT_FOUND(200001, "其他押金账单不存在"),

    /**
     * 日常费用账单
     * */
    BILL_ROUTINE_IS_NOT_FOUND(21000,"账单不存在"),
    BILL_UPDATE_FAILED(21001,"账单更新失败"),
    BILL_OWE_ZERO(21002,"账单欠缴为0"),
    BILL_PAY_ERROR(21003,"账单支付错误"),

    /**
     * 商铺
     * */
    SHOP_IS_NOT_FOUND(22000,"商铺不存在"),
    SHOP_IS_RENT(22001,"商铺已出租"),

    WIWIDE_INFO_NOT_FOUND(23001,"迈外迪信息未找到"),
    WIWIDE_INFO_NOT_READY(23002,"迈外迪信息未就绪"),

    /**
     * 审批流
     */
    FLOW_FAIL(24000, "审批流操作出错"),
    FLOW_INST_NOT_EXIST(24001, "任务不存在"),
    /**
     * 微信第三方
     */
    WEAPP_APPID_NOT_AUTH(24100, "appid未授权"),
    WEAPP_BASIC_SET_ERR(24101, "基础配置错误"),
    WEAPP_BASIC_SET_DOMAIN_ERR(24102, "基础服务器域名配置错误"),
    WEAPP_EXT_SET_ERR(24103, "扩展配置错误"),
    WEAPP_CODE_COMMIT_ERR(24104, "code提交失败"),
    WEAPP_AUDIT_ERR(24105, "提交审核失败"),
    WEAPP_HAD_AUDITING(24106, "已有审核中"),
    WEAPP_NOT_AUDITED(24107, "审核未通过"),
    WEAPP_APP_RELEASEED(24108, "已发布"),

    WECHAT_LOGIN_KEY_OVERTIME(24130, "已过期"),
    WECHAT_LOGIN_USER_SELECT(24131, "请选择要登录的用户"),
    WECHAT_LOGIN_NOT_BIND(24132, "您的微信号未绑定,请登录后绑定"),

    /**
     * 屏广告
     */
    SCREENAD_NOT_FOUND(25000, "屏广告未找到"),

    /**
     * IOT设备
     */
    DEVICE_NOT_FOUND(26000, "设备未注册到系统"),
    DEVICE_ALREADY_EXIST(26001, "设备已经存在"),
    DEVICE_QRCODE_GET_FAILED(26002, "微信二维码生成失败,请重试"),
    /**
     * 消息组件
     */
    MSG_MODEL_NOT_FOUND(27000, "找不到短信模板"),
    MSG_CONFIG_NOT_FOUND(27001, "找不到短信配置"),

    /**
     * 拼团
     */
    ORDER_GROUP_COOPERATING_FAILD(28001, "参团失败"),
    ORDER_GROUP_COOPERATING_FINISHED(28002, "拼团人数已满"),
    ;

    private int code;
    private String message;

    ErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage(Object... param) {
        if (param.length == 0) {
            return message;
        }
        return MessageFormat.format(message, param);
    }

    public static ErrorCode getByCode(int code) {
        ErrorCode[] values = ErrorCode.values();
        for (ErrorCode value : values) {
            if (value.getCode() == code) {
                return value;
            }

        }
        return null;
    }
}
