package com.m2pool.system.api.factory;

import com.m2pool.common.core.Result.R;
import com.m2pool.system.api.RemoteMailService;
import com.m2pool.system.api.entity.EmailEntity;
import com.m2pool.system.api.entity.EmailTemplateEntity;
import com.m2pool.system.api.entity.GetEmailCodeEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 文件服务降级处理
 *
 * @author dy
 */
@Component
public class RemoteMailFallbackFactory implements FallbackFactory<RemoteMailService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteMailFallbackFactory.class);

    @Override
    public RemoteMailService create(Throwable cause)
    {
        return new RemoteMailService() {
            @Override
            public R<?>
            sendAddCreditEmailCode(GetEmailCodeEntity entity) {
                return R.fail("提现邮箱验证发送失败:" + cause.getMessage());
            }

            @Override
            public R<?> sendTextMail(@RequestBody EmailEntity entity){
                return R.fail("邮箱发送失败:" + cause.getMessage());
            }

            @Override
            public R<?> sendHtmlMailMessage(@RequestBody EmailTemplateEntity entity) {
                return R.fail("邮箱发送失败:" + cause.getMessage());
            }

        };
    }
}
