package com.kym.common.exception;

/**
 * 平台通信异常
 * 用于处理与第三方平台（如 EN+）通信时的异常
 *
 * @author skyline
 */
public class PlatformCommunicationException extends BusinessException {

    private static final long serialVersionUID = 1L;

    private final String platformName;
    private final String apiName;

    public PlatformCommunicationException(String platformName, String message) {
        super("连接" + platformName + "平台失败：" + message);
        this.platformName = platformName;
        this.apiName = null;
    }

    public PlatformCommunicationException(String platformName, String apiName, String message) {
        super("调用" + platformName + "平台接口" + apiName + "失败：" + message);
        this.platformName = platformName;
        this.apiName = apiName;
    }

    public PlatformCommunicationException(String platformName, Throwable cause) {
        super("连接" + platformName + "平台异常：" + cause.getMessage());
        this.platformName = platformName;
        this.apiName = null;
        this.initCause(cause);
    }

    public String getPlatformName() {
        return platformName;
    }

    public String getApiName() {
        return apiName;
    }

    /**
     * 平台认证失败异常
     */
    public static class PlatformAuthException extends PlatformCommunicationException {
        public PlatformAuthException(String platformName) {
            super(platformName, "认证失败，请检查密钥配置");
        }
    }

    /**
     * 平台超时异常
     */
    public static class PlatformTimeoutException extends PlatformCommunicationException {
        public PlatformTimeoutException(String platformName, String apiName) {
            super(platformName, apiName, "请求超时，请稍后重试");
        }
    }

    /**
     * 平台数据格式异常
     */
    public static class PlatformDataFormatException extends PlatformCommunicationException {
        public PlatformDataFormatException(String platformName, String message) {
            super(platformName, "数据格式错误：" + message);
        }
    }
}
