package cn.nianxx.thhotel.platform.message.control;

import cn.nianxx.thhotel.platform.hotel.service.HotelContextException;
import java.util.Map;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * SourceMessage 查询接口异常处理。只返回安全错误码和摘要信息，不暴露内部堆栈。
 */
@RestControllerAdvice(assignableTypes = SourceMessageController.class)
public class SourceMessageControllerAdvice {

    /**
     * 处理酒店上下文解析失败，例如单酒店未配置、多 ACTIVE 酒店或当前用户无权限访问。
     */
    @ExceptionHandler(HotelContextException.class)
    public ResponseEntity<Map<String, Object>> handleHotelContextException(HotelContextException exception) {
        return ResponseEntity.status(exception.getStatus())
                .body(Map.of(
                        "error_code", exception.getErrorCode(),
                        "message", exception.getMessage()));
    }
}
