package com.yami.shop.common.exception;

import com.esotericsoftware.minlog.Log;
import com.yami.shop.common.util.IBasicInfo;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>TODO</p>
 *
 * @author mr wang
 * @version 1.0.0
 * @since 2025-08-26
 */
@Slf4j
@Setter
@Getter
public class GlobalException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    protected String errorCode;
    /**
     * 错误信息
     */
    protected String errorMsg;

    public GlobalException() {
        super();
    }

    public GlobalException(IBasicInfo IBasicInfo) {
        super(String.valueOf(IBasicInfo.getCode()));
        this.errorCode = String.valueOf(IBasicInfo.getCode());
        this.errorMsg = IBasicInfo.getValue();
    }

    public GlobalException(IBasicInfo IBasicInfo, Throwable cause) {
        super(String.valueOf(IBasicInfo.getCode()), cause);
        this.errorCode = String.valueOf(IBasicInfo.getCode());
        this.errorMsg = IBasicInfo.getValue();
    }

    public GlobalException(String errorMsg) {
        super(errorMsg);
        log.error(errorMsg, this);
        this.errorMsg = errorMsg;
    }

    public GlobalException(String errorCode, String errorMsg) {
        super(errorCode);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public GlobalException(String errorCode, String errorMsg, Throwable cause) {
        super(errorCode, cause);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }



    public String getMessage() {
        return errorMsg;
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }
}
