package cn.nianxx.thhotel.workflows.reservation.control;

import cn.nianxx.thhotel.workflows.reservation.common.result.ReservationWorkflowErrorResponse;
import cn.nianxx.thhotel.workflows.reservation.service.impl.ReservationTaskWorkflowException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Reservation 任务接口统一异常处理。错误响应不暴露内部堆栈或原始 AI payload。
 */
@RestControllerAdvice(assignableTypes = {
        ReservationTaskController.class,
        ReservationFrontendQueryController.class,
        ReservationDemoDataController.class
})
public class ReservationTaskControllerAdvice {

    /**
     * 处理任务详情和人工转换阶段的受控业务异常。
     */
    @ExceptionHandler(ReservationTaskWorkflowException.class)
    public ResponseEntity<ReservationWorkflowErrorResponse> handleTaskWorkflowException(
            ReservationTaskWorkflowException exception) {
        return ResponseEntity.status(exception.getStatus())
                .body(new ReservationWorkflowErrorResponse(
                        exception.getErrorCode(),
                        exception.getMessage(),
                        exception.getDetails()));
    }
}
