package com.vctgo.system.api.factory;

import com.vctgo.common.core.domain.R;
import com.vctgo.system.api.RemoteClassService;
import com.vctgo.system.api.domain.SysClassSetting;
import com.vctgo.system.api.domain.SysReLocationArea;
import com.vctgo.system.api.domain.SysReLocationClass;
import com.vctgo.system.api.domain.dto.BindClassUserDto;
import com.vctgo.system.api.domain.dto.SysClassSettingDto;
import com.vctgo.system.api.domain.dto.SysReClassUserDto;
import com.vctgo.system.api.domain.dto.ToySysClassSettingDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 *
 * @author vctgo
 */
@Component
public class RemoteClassFallbackFactory implements FallbackFactory<RemoteClassService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteClassFallbackFactory.class);

    @Override
    public RemoteClassService create(Throwable throwable) {
        log.error("班级服务调用失败:{}", throwable.getMessage());
        return new RemoteClassService() {
            @Override
            public R<List<SysClassSetting>> getClassList(SysClassSettingDto sysClassSettingDto) {
                return R.fail("获取班级列表失败:" + throwable.getMessage());
            }

            @Override
            public R<SysClassSetting> getClassInfo(Long id, String source) {
                return R.fail("获取班级数据失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysClassSetting>> getUserClassDataList(Long userId, Integer bindUserPosition, String source) {
                return R.fail("获取班级列表失败:" + throwable.getMessage());
            }

            @Override
            public R<Long[]> getLocationIdList(Long[] ids,String source) {
                return R.fail("通过班级信息获取位置失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysReLocationArea>> selectLocationAndAreaByClassId(String classId) {
                return R.fail("通过班级信息获取位置和区域失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysReLocationArea>> selectLocationAndAreaByGradeInAndClass(String[] gradeIn, String[] classIds,String selectType) {
                return R.fail("通过年级或班级获取位置和区域失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysReLocationArea>> selectLocationAndAreaByLocationId(String[] locationIds) {
                return R.fail("通过位置获取位置和区域失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysReLocationClass>> selectLocationIdAndClass() {
                return R.fail("获取位置和班级失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysClassSetting>> getClassListByLocationId(Long locationId, String source) {
                return R.fail("通过班级信息获取位置失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysClassSetting>> getClassSetting(String[] locationIds, String source) {
                return R.fail("通过位置获取班级信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysClassSetting>> selectClassSettingAndLocation(String tenantId) {
                return R.fail("获取班级与位置的关联失败:" + throwable.getMessage());
            }

            @Override
            public R<SysClassSetting> getClassSettingInfo(Long id, String source) {
                return R.fail("获取班级数据失败:" + throwable.getMessage());
            }

            @Override
            public R<BindClassUserDto> getClassAllocationDetail(Long classId, Integer bindUserPosition) {
                return R.fail("获取班级配置的人员明细失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysClassSetting>> classListByBindInfo() {
                return R.fail("根据班级绑定人员获取班级列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysReClassUserDto>> getClassReUserList(SysReClassUserDto sysReClassUserDto) {
                return R.fail("根据班级绑定人员获取班级列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysClassSettingDto>> getClassListByLocationIdList(List<Long> locationIds) {
                return R.fail("根据位置id集合取班级列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<ToySysClassSettingDto>> getLocationByGradeIn(ToySysClassSettingDto sysClassSettingDto) {
                return R.fail("根据年级集合取班级位置失败:" + throwable.getMessage());
            }
        };
    }
}
