package tech.easyflow.ai.document.exception;

/**
 * 文档解析桥接层异常。
 *
 * <p>桥接层负责把底层文档服务异常和文件加载异常转换为稳定语义，
 * 供上层业务按场景进行处理。</p>
 *
 * @author Codex
 * @since 2026-04-14
 */
public class DocumentParseBridgeException extends RuntimeException {

    private final String code;

    public DocumentParseBridgeException(String code, String message) {
        super(message);
        this.code = code;
    }

    public DocumentParseBridgeException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    /**
     * 获取稳定错误码。
     *
     * @return 错误码
     */
    public String getCode() {
        return code;
    }

    public static DocumentParseBridgeException serviceNotEnabled() {
        return new DocumentParseBridgeException(
            "service_not_enabled",
            "统一文档解析服务未启用，请先配置 easy-agents.document.ocr.provider=mineru"
        );
    }

    public static DocumentParseBridgeException serviceNotEnabled(String message) {
        return new DocumentParseBridgeException("service_not_enabled", message);
    }

    public static DocumentParseBridgeException unsupportedSource(String message) {
        return new DocumentParseBridgeException("unsupported_source", message);
    }

    public static DocumentParseBridgeException sourceLoadFailed(String message, Throwable cause) {
        return new DocumentParseBridgeException("source_load_failed", message, cause);
    }

    public static DocumentParseBridgeException requestBuildFailed(String message, Throwable cause) {
        return new DocumentParseBridgeException("request_build_failed", message, cause);
    }

    public static DocumentParseBridgeException requestBuildFailed(String message) {
        return new DocumentParseBridgeException("request_build_failed", message);
    }

    public static DocumentParseBridgeException parseFailed(String message, Throwable cause) {
        return new DocumentParseBridgeException("parse_failed", message, cause);
    }

    public static DocumentParseBridgeException parseFailed(String message) {
        return new DocumentParseBridgeException("parse_failed", message);
    }

    public static DocumentParseBridgeException taskFailed(String message, Throwable cause) {
        return new DocumentParseBridgeException("task_failed", message, cause);
    }

    public static DocumentParseBridgeException taskFailed(String message) {
        return new DocumentParseBridgeException("task_failed", message);
    }

    public static DocumentParseBridgeException resultFetchFailed(String message, Throwable cause) {
        return new DocumentParseBridgeException("result_fetch_failed", message, cause);
    }

    public static DocumentParseBridgeException resultFetchFailed(String message) {
        return new DocumentParseBridgeException("result_fetch_failed", message);
    }
}
