package cn.sikey.mcdisk.feign.fallback;

import cn.hutool.http.HttpStatus;
import cn.sikey.framework.common.exception.ServiceException;
import cn.sikey.mcdisk.entity.ActivateCloudPhotoAlbumMessage;
import cn.sikey.mcdisk.entity.MessagingPublishResponse;
import cn.sikey.mcdisk.entity.NotifyParentsSuccessfulActivationMessage;
import cn.sikey.mcdisk.entity.ReloginOnWwatchMessage;
import cn.sikey.mcdisk.feign.ApiMessageFeignService;
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 ApiMessageFallbackFactory implements FallbackFactory<ApiMessageFeignService> {

    /**
     * 获取用户登录信息
     *
     * @param cause 用户登录信息
     * @return
     */
    @Override
    public ApiMessageFeignService create(Throwable cause) {
        return new ApiMessageFeignService() {
            @Override
            public MessagingPublishResponse reloginOnWwatch(ReloginOnWwatchMessage request) {
                log.error("[消息中心feign降级服务]调用手表重新登录发消息失败：{}", cause);
                throw new ServiceException(HttpStatus.HTTP_INTERNAL_ERROR, "调用手表重新登录发消息失败");
            }

            @Override
            public MessagingPublishResponse activateCloudPhotoAlbum(ActivateCloudPhotoAlbumMessage request) {
                log.error("[消息中心feign降级服务]调用开通云相册服务通知手表失败：{}", cause);
                throw new ServiceException(HttpStatus.HTTP_INTERNAL_ERROR, "调用开通云相册服务通知手表失败");
            }

            @Override
            public MessagingPublishResponse notifyParentsSuccessfulActivation(NotifyParentsSuccessfulActivationMessage request) {
                log.error("[消息中心feign降级服务]调用开通成功通知家长失败：{}", cause);
                throw new ServiceException(HttpStatus.HTTP_INTERNAL_ERROR, "调用开通成功通知家长失败");
            }

            @Override
            public MessagingPublishResponse notifyParentsAuthorization(NotifyParentsSuccessfulActivationMessage request) {
                log.error("[消息中心feign降级服务]调用通知家长授权失败：{}", cause);
                throw new ServiceException(HttpStatus.HTTP_INTERNAL_ERROR, "调用通知家长授权失败");
            }
        };
    }
}
