package cn.sikey.mcdisk.feign.fallback;

import cn.hutool.http.HttpStatus;
import cn.sikey.framework.common.exception.ServiceException;
import cn.sikey.mcdisk.entity.GetPhoneNumberRequest;
import cn.sikey.mcdisk.entity.GetPhoneNumberResponse;
import cn.sikey.mcdisk.feign.ApiChildFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;


/**
 * @Author: nelson
 * @Date: 2025/5/29
 * @Description: 儿童feign降级服务
 */
@Slf4j
@Component
public class ApiChildFallbackFactory implements FallbackFactory<ApiChildFeignService> {

    /**
     * 获取用户登录信息
     *
     * @param cause 用户登录信息
     * @return
     */
    @Override
    public ApiChildFeignService create(Throwable cause) {
        return new ApiChildFeignService() {
            @Override
            public GetPhoneNumberResponse getPhoneNumber(GetPhoneNumberRequest request) {
                log.error("[儿童中心feign降级服务]调用获取儿童手机号失败：{0}", cause);
                throw new ServiceException(HttpStatus.HTTP_INTERNAL_ERROR, "调用获取儿童手机号失败");
            }

        };
    }
}
