package com.xueyi.system.api.meeting.feign.factory;

import com.alibaba.fastjson2.JSONObject;
import com.xueyi.common.core.web.result.R;
import com.xueyi.system.api.meeting.domain.dto.DmMeetingOrdersDto;
import com.xueyi.system.api.meeting.domain.dto.DmMeetingRoomsDto;
import com.xueyi.system.api.meeting.feign.RemoteMeetingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 会议室服务 降级处理
 *
 * @author xueyi
 */
@Slf4j
@Component
public class RemoteMeetingFallbackFactory implements FallbackFactory<RemoteMeetingService> {

    @Override
    public RemoteMeetingService create(Throwable throwable) {
        log.error("会议室服务调用失败:{}", throwable.getMessage());
        return new RemoteMeetingService() {


            @Override
            public R<List<DmMeetingRoomsDto>> roomListInner(Long deptId, Long enterpriseId, String sourceName, String source) {
                return R.fail("获取会议室列表失败:" + throwable.getMessage());
            }

            @Override
            public JSONObject saveInner(DmMeetingOrdersDto order, Long enterpriseId, String sourceName, String source) {
                return null;
            }


            @Override
            public JSONObject delInner(Long id, Long enterpriseId, String sourceName, String source) {
                return  R.fail("删除会议室预约失败:" + throwable.getMessage()).toJson();
            }

            @Override
            public JSONObject personListInner(Long orderBy, Long enterpriseId, String sourceName, String source) {
                return  R.fail("获取个人会议室预约列表失败:" + throwable.getMessage()).toJson();
            }

            @Override
            public JSONObject listsInner(String dateStr, Long spaceId, Long enterpriseId, String sourceName, String source) {
                return  R.fail("获取会议室预约列表失败:" + throwable.getMessage()).toJson();
            }

            @Override
            public JSONObject listsAllInner( Long enterpriseId, String sourceName, String source) {
                return  R.fail("获取会议室预约列表失败:" + throwable.getMessage()).toJson();
            }

            @Override
            public JSONObject listsByDate(String dateStr, Long enterpriseId, String sourceName, String source) {
                return  R.fail("获取会议室预约列表失败:" + throwable.getMessage()).toJson();
            }

            @Override
            public JSONObject listAllInner(String dateStr, Long spaceId, Long enterpriseId, String sourceName, String source) {
                return  R.fail("获取会议室预约列表失败:" + throwable.getMessage()).toJson();
            }

            @Override
            public List<JSONObject> recent(Long deptId, String dateStr, Long roomId, String startTime, Long enterpriseId, String sourceName, String source) {
                List js = new ArrayList<>();
                js.add(R.fail("获取会议室可预约列表失败:" + throwable.getMessage()).toJson());
                return js;
            }

            @Override
            public List<JSONObject> recent(Long deptId, Long enterpriseId, String sourceName, String source) {
                List js = new ArrayList<>();
                js.add(R.fail("获取会议室可预约列表失败:" + throwable.getMessage()).toJson());
                return js;
            }

            @Override
            public R<List<JSONObject>> ableOrderList(String devId, String dateStr, Long roomId, String startTime) {
                return null;
            }

            @Override
            public JSONObject queryExist(Long roomId, String dateStr, String startTime, Long enterpriseId, String sourceName, String source) {
                return null;
            }

            @Override
            public JSONObject queryExistOrder(Long roomId, String dateStr, String startTime, Integer duration, Long enterpriseId, String sourceName, String source) {
                return null;
            }
        };
    }
}