package com.ga.common.exception;

import lombok.Getter;

/**
 * 업무 예외. 서비스에서 throw new BizException(ErrorCode.XXX) 형태로 사용.
 */
@Getter
public class BizException extends RuntimeException {

    private final ErrorCode errorCode;
    private final String customMessage;

    public BizException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.errorCode = errorCode;
        this.customMessage = null;
    }

    public BizException(ErrorCode errorCode, String customMessage) {
        super(customMessage);
        this.errorCode = errorCode;
        this.customMessage = customMessage;
    }

    public BizException(ErrorCode errorCode, Throwable cause) {
        super(errorCode.getMessage(), cause);
        this.errorCode = errorCode;
        this.customMessage = null;
    }

    public String getDisplayMessage() {
        return customMessage != null ? customMessage : errorCode.getMessage();
    }
}
