package com.bawei.es.remote.factory;

import com.bawei.common.core.domain.R;
import com.bawei.es.remote.EsIndexRemoteService;
import lombok.extern.log4j.Log4j2;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Log4j2
public class EsIndexRemoteFactory implements FallbackFactory<EsIndexRemoteService> {
    @Override
    public EsIndexRemoteService create(Throwable cause) {
        return new EsIndexRemoteService() {
            @Override
            public R createIndex(String indexName, Map<String, Object> docMsg) {
                log.error("远程调用创建索引服务失败:{}-{}-{}-{}",indexName,docMsg,cause.getMessage(),cause);
                return R.fail();
            }

            @Override
            public R findIndex(String indexName) {
                log.error("远程调用查询索引服务失败:{}-{}-{}",indexName,cause.getMessage(),cause);
                return R.fail();
            }

            @Override
            public R getMapping(String indexName) {
                log.error("远程调用获取Mapping服务失败:{}-{}-{}",indexName,cause.getMessage(),cause);
                return R.fail();
            }

            @Override
            public R deleteIndex(String indexName) {
                log.error("远程调用删除索引服务失败:{}-{}-{}",indexName,cause.getMessage(),cause);
                return R.fail();
            }

            @Override
            public R updateIndex(String indexName, Map<String, Object> docMsg) {
                log.error("远程调用修改索引服务失败:{}-{}-{}{}",indexName,docMsg,cause.getMessage(),cause);
                return R.fail();
            }
        };
    }
}
