package com.zd.system.api.factory;

import com.zd.common.core.domain.R;
import com.zd.system.api.domain.SubQueryConfig;
import com.zd.system.api.laboratory.CabinetV2Lock;
import com.zd.system.api.laboratory.RemoteSubQueryService;
import com.zd.system.api.laboratory.domain.CabinetLock;
import com.zd.system.api.laboratory.domain.LabSubject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class RemoteSubQueryFallbackFactory implements FallbackFactory<RemoteSubQueryService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteSubQueryFallbackFactory.class);


    @Override
    public RemoteSubQueryService create(Throwable cause) {
        log.error("实验室服务调用失败:{}", cause.getMessage());
        return new RemoteSubQueryService() {

            /**
             * 查询实验室详情
             */
            @Override
            public R<Object> getSafeWarnCount(Long id, SubQueryConfig subQueryConfig) {
                return R.fail("查询实验室详情失败:" + cause.getMessage());
            }

            /**
             * 查询实验室数据列表- 数据权限（包括负责人）
             */
            @Override
            public R<Object> querySubCListVO(Map<String,Object> appSubQuery) {
                return R.fail("查询实验室数据列表失败:" + cause.getMessage());
            }

            /**
             * 查询管理实验室和预案执行数量
             */
            @Override
            public R<Map<String,Object>> querySubCListVO() {
                return R.fail("查询管理实验室和预案执行数量失败:" + cause.getMessage());
            }

            @Override
            public R<List<LabSubject>> listByIds(List<Long> ids) {
                return R.fail("查询管理实验室失败:" + cause.getMessage());
            }

            @Override
            public R<List<LabSubject>> listByName(String name) {
                return R.fail("查询管理实验室失败:" + cause.getMessage());
            }

            @Override
            public R cabinetLock(CabinetLock cabinetLock) {
                return R.fail("柜锁操作失败：" + cause.getMessage());
            }

            @Override
            public R cabinetV2OpenLock(CabinetV2Lock cabinetV2Lock) {
                return R.fail("柜锁开锁失败：" + cause.getMessage());
            }

            @Override
            public R cabinetV2CloseLock(CabinetV2Lock cabinetV2Lock) {
                return R.fail("柜锁关锁失败：" + cause.getMessage());
            }
        };
    }
}
