package top.imwork.window.silos.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import top.imwork.commons.core.enums.HttpStatusCodeEnum;
import top.imwork.commons.core.pojo.ResponseMsg;

import java.util.Map;

/**
 * Copyright (C), 2015-2026
 * FileName: FileUploadException
 * Author<作者姓名>:   silos
 * CreateTime<创建时间>:   2026/1/15 22:12
 * UpdateTime<修改时间>:   2026/1/15 22:12
 * Description〈功能简述〉: 文件上传异常
 * History<历史描述>:
 * Since<版本号>: 1.0.0
 */
@Slf4j
public class FileUploadException extends RuntimeException{
    /**
     * 文件大小超过限制异常
     */
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public ResponseMsg handleMaxSizeException(
            MaxUploadSizeExceededException e) {
        log.warn("文件大小超过限制", e);
        return ResponseMsg.buildResponse(HttpStatusCodeEnum.BAD_REQUEST.getCode(), "文件大小超过限制");
    }

    /**
     * 文件上传相关异常
     */
    @ExceptionHandler(IllegalArgumentException.class)
    public ResponseMsg handleIllegalArgumentException(
            IllegalArgumentException e) {

        log.warn("文件上传参数错误", e);
        return ResponseMsg.fail(e.getMessage());
    }
}