package com.crunii.micro.feign.client.fallbackfactory;

import com.crunii.micro.common.dto.Result;
import com.crunii.micro.feign.client.SmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author qiaolin
 * @version 1.0
 * @date 2023/6/29 12:40
 */
@Component
public class SmsServiceFallbackFactory implements FallbackFactory<SmsService> {
    private static final Logger logger = LoggerFactory.getLogger(ObsServiceFallbackFactory.class);

    @Override
    public SmsService create(Throwable cause) {
        logger.error("fallback; exception was: {}", cause.toString());
        logger.error("fallback; reason was: {}", cause.getMessage());
        return new SmsService() {
            @Override
            public Result<String> smsCode(String phone) {
                Result<String> result = new Result();
                result.setSuccess(false);
                result.setMsg("smsCode接口调用失败");
                return result;
            }

            @Override public Result<String> updateTestFile() {
                Result<String> result = new Result();
                result.setSuccess(false);
                result.setMsg("smsCode接口调用失败");
                return result;
            }

            @Override
            public Result<String> sendMessage(String phone, String content) {
                Result<String> result = new Result();
                result.setSuccess(false);
                result.setMsg("smsCode接口调用失败");
                return result;
            }

            @Override
            public Result<String> sendSms(String phone, String templateCode, String fillData) {
                Result<String> result = new Result();
                result.setSuccess(false);
                result.setMsg("smsCode接口调用失败");
                return result;
            }
        };
    }
}
