package com.yuchen.saas.message.api.feign.message;

import com.yuchen.saas.message.api.dto.PmgBatMessageDto;
import com.yuchen.saas.message.api.dto.PmgBatMessageQueryDto;
import com.yuchen.saas.message.api.util.MessageFeignFallbackUtils;
import com.yuchen.saas.message.api.vo.PmgBatMessageVo;
import feign.hystrix.FallbackFactory;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 消息中心feign调用
 * </p>
 *
 * @author caiwq
 * @since 2024-02-28
 */
@Component
public class MessageFeignFallback implements FallbackFactory<MessageFeignServer> {

    @Override
    public MessageFeignServer create(Throwable throwable) {
        return new MessageFeignServer() {

            @Override
            public R<Boolean> saveMessage(PmgBatMessageDto messageDto) {
                return MessageFeignFallbackUtils.printLogAndReturn(throwable);
            }

            @Override
            public R<Boolean> saveBatchMessage(List<PmgBatMessageDto> messageList) {
                return MessageFeignFallbackUtils.printLogAndReturn(throwable);
            }

            @Override
            public R<Boolean> deleteMessage(Long id) {
                return MessageFeignFallbackUtils.printLogAndReturn(throwable);
            }

            @Override
            public R<NestPage<PmgBatMessageVo>> getMessagePageList(PmgBatMessageQueryDto queryDto) {
                return MessageFeignFallbackUtils.printLogAndReturn(throwable);
            }
        };
    }
}
