package com.microservices.system.api.factory;

import com.microservices.common.core.domain.R;
import com.microservices.system.api.RemoteZoneService;
import com.microservices.system.api.domain.SysDept;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 特色专区服务降级处理
 *
 * @author microservices
 */
@Component
public class RemoteZoneFallbackFactory implements FallbackFactory<RemoteZoneService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteZoneFallbackFactory.class);

    @Override
    public RemoteZoneService create(Throwable throwable) {
        log.error("特色专区服务调用失败:{}", throwable.getMessage());
        return new RemoteZoneService() {

            @Override
            public R<Long> autoAddZoneByDept(Long deptId, String source) {
                return R.fail("新增组织时自动创建特色专区失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> autoUpdateZoneByDept(SysDept dept, String source) {
                return R.fail("更新组织时自动更新特色专区失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getZoneJSONByZoneId(Long zoneId, String source) {
                return R.fail("通过专区Id获取专区对应专区详情Json对象失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getZoneJSONByDeptId(Long zoneId, String source) {
                return R.fail("通过组织Id获取专区对应专区详情Json对象失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> getZoneHomePageCmsSizeByDeptId(Long deptId, String source) {
                return R.fail("通过组织Id获取专区详情对象失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Long>> checkUsersIsMemberInDept(Long deptId, Long[] userIds, String source) {
                return R.fail("检查并获取组织下的会员列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Long>> checkUserIsMemberInDepts(Long userId, Long[] deptIds, String source) {
                return R.fail("检查并获取用户所在组织的会员列表失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> deleteByDeptName(String deptName, String source) {
                return R.fail("通过组织名称删除特色专区失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> lockCmsByDeptId(Long deptId, Integer lockStatus, String source) {
                return R.fail("通过组织id锁定/解锁专区资讯失败:" + throwable.getMessage());
            }
        };
    }
}
