package cn.reghao.tnb.file.app.config;

import cn.reghao.tnb.file.app.rpc.OssClientManager;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author reghao
 * @date 2026-04-27 16:22:31
 */
@Aspect
@Component
public class ClientAvailabilityAspect {
    private final OssClientManager ossClientManager;

    public ClientAvailabilityAspect(OssClientManager ossClientManager) {
        this.ossClientManager = ossClientManager;
    }

    // 拦截 StoreServiceWrapperRouter 下的所有公共方法
    @Around("execution(* cn.reghao.tnb.file.app.rpc.StoreServiceWrapperRouter.*(..))")
    public Object checkOssClientAvailability(ProceedingJoinPoint joinPoint) throws Throwable {
        if (ossClientManager.getOssClient() == null) {
            throw new RuntimeException("OssClient 未初始化");
        }
        return joinPoint.proceed();
    }
}
