package com.test.musichouduan.controller;

import com.test.musichouduan.dto.Result;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * 回退控制器
 * 处理所有未匹配的请求
 * 使用Order注解指定优先级，数值越大优先级越低
 */
@RestController
@Order(Integer.MAX_VALUE)
public class FallbackController {

    /**
     * 处理所有非API请求
     *
     * @param request HTTP请求
     * @param response HTTP响应
     * @return 响应结果
     */
    @RequestMapping({"/1", "/2", "/3", "/4", "/5", "/6", "/7", "/8", "/9"})
    public Result<String> handleFallback(HttpServletRequest request, HttpServletResponse response) {
        // 设置HTTP状态码为404
        response.setStatus(HttpStatus.NOT_FOUND.value());

        // 返回错误信息
        return Result.error(HttpStatus.NOT_FOUND.value(), "资源不存在: " + request.getRequestURI());
    }
}
