package com.zd.system.api.message.factory;

import com.zd.common.core.domain.R;
import com.zd.common.core.template.TemplateResult;
import com.zd.system.api.message.RemoteMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class RemoteMessageFallbackFactory implements FallbackFactory<RemoteMessageService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteMessageFallbackFactory.class);

    @Override
    public RemoteMessageService create(Throwable throwable) {
        log.error("消息服务调用失败:{}", throwable.getMessage());
        return new RemoteMessageService() {
            @Override
            public R<TemplateResult> backlog(Long userId, String backlogName, String remark) {
                return R.fail("待办事项消息发送失败:" + throwable.getMessage());
            }

            @Override
            public R<TemplateResult> check(Long userId, Integer checkType, Integer checkStatus, Date checkTime,Long taskId) {
                return R.fail("审核消息发送失败:" + throwable.getMessage());
            }

            @Override
            public R<TemplateResult> stuCheck(Long userId, Integer checkType, Integer checkStatus, Date checkTime, Long taskId) {
                return R.fail("审核消息发送失败:" + throwable.getMessage());
            }

            @Override
            public R<TemplateResult> storageOut(Long userId, String outType, Date outTime) {
                return R.fail("出库确认通知失败:" + throwable.getMessage());
            }

            @Override
            public R<TemplateResult> waitCheck(Long userId, Integer checkType, String name, Date applyTime) {
                return R.fail("待审核消息发送失败:" + throwable.getMessage());
            }

            @Override
            public R<TemplateResult> sendAlarm(List<Long> userIds, String address) {
                return R.fail("气瓶超出范围通知:" + throwable.getMessage());
            }
        };
    }
}
