package jnpf.util.auth.fallback;

import jnpf.util.auth.V2AuthPermissionApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 无有效熔断占位数据：调用失败时直接失败，避免将空列表误判为「无人事数据权限」。
 */
@Slf4j
@Component
public class V2AuthPermissionApiFallback implements FallbackFactory<V2AuthPermissionApi> {

    @Override
    public V2AuthPermissionApi create(Throwable cause) {
        if (cause != null) {
            log.error("V2AuthPermissionApi 调用失败(将向上抛出，不返回空权限): {}", cause.getMessage(), cause);
        }
        return () -> {
            String msg = "人事数据权限服务暂不可用(V2AuthPermissionApi/getLoginUserAuthOrganizeIds)，请稍后重试";
            if (cause != null) {
                throw new IllegalStateException(msg, cause);
            }
            throw new IllegalStateException(msg);
        };
    }
}
