package com.agileboot.common.core.exception;

import cn.hutool.core.text.StrFormatter;
import com.agileboot.common.core.exception.error.ErrorCodeInterface;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serial;

/**
 * @Author cuiJiaWang
 * @Create 2025-08-12 16:32
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
public class BizException extends RuntimeException {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误提示
     */
    private String message;

    public BizException(String message) {
        this.message = message;
    }

    public BizException(ErrorCodeInterface errorCode) {
        this.code = errorCode.code();
        this.message = errorCode.message();
    }

    public BizException(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    public BizException(String message, Object... args) {
        this.message = StrFormatter.format(message, args);
    }

    public BizException(ErrorCodeInterface errorCode, Object... args) {
        this.message = StrFormatter.format(errorCode.message(), args);
    }
}
