package org.dromara.member.exception;

/**
 * 文件相关异常
 *
 * @author pengles
 */
public class FileException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    private Integer code;

    private String message;

    private String detailMessage;

    public FileException() {
    }

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

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

    public FileException(String message, Throwable e) {
        super(message, e);
        this.message = message;
    }

    public FileException(String message, Integer code, Throwable e) {
        super(message, e);
        this.message = message;
        this.code = code;
    }

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

    public FileException(String message, Integer code, String detailMessage, Throwable e) {
        super(message, e);
        this.message = message;
        this.code = code;
        this.detailMessage = detailMessage;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getDetailMessage() {
        return detailMessage;
    }

    public void setDetailMessage(String detailMessage) {
        this.detailMessage = detailMessage;
    }

    // 静态工厂方法
    public static FileException fileEmpty() {
        return new FileException("上传文件不能为空", 40001);
    }

    public static FileException fileSizeExceeded(long maxSize) {
        return new FileException("文件大小超过限制", 40002, "最大允许大小: " + maxSize + "MB");
    }

    public static FileException unsupportedFileType(String fileType) {
        return new FileException("不支持的文件类型", 40003, "文件类型: " + fileType);
    }

    public static FileException uploadFailed(String reason) {
        return new FileException("文件上传失败", 40004, reason);
    }

    public static FileException fileNotFound(Long fileId) {
        return new FileException("文件不存在", 40005, "文件ID: " + fileId);
    }

    public static FileException downloadFailed(String reason) {
        return new FileException("文件下载失败", 40006, reason);
    }

    public static FileException deleteFailed(String reason) {
        return new FileException("文件删除失败", 40007, reason);
    }

    public static FileException accessDenied(Long fileId) {
        return new FileException("无权限访问文件", 40008, "文件ID: " + fileId);
    }

    public static FileException storageServiceError(String service) {
        return new FileException("存储服务异常", 40009, "服务: " + service);
    }

    public static FileException md5CalculationFailed() {
        return new FileException("文件MD5计算失败", 40010);
    }

    public static FileException invalidFileName(String fileName) {
        return new FileException("无效的文件名", 40011, "文件名: " + fileName);
    }

    public static FileException fileAlreadyExists(String fileName) {
        return new FileException("文件已存在", 40012, "文件名: " + fileName);
    }
}