package com.zd.system.api.speak.factory;

import com.zd.common.core.domain.R;
import com.zd.system.api.domain.PlayVo;
import com.zd.system.api.speak.RemoteSpeakService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *
 */
@Component
public class RemoteSpeakFallbackFactory implements FallbackFactory<RemoteSpeakService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSpeakFallbackFactory.class);

    @Override
    public RemoteSpeakService create(Throwable cause) {
        return new RemoteSpeakService() {
            @Override
            public String textParseUrl(Integer speed, Integer volume, String text) {
                log.info("语音转化失败:" + cause.getMessage());
                return "语音转化失败:" + cause.getMessage();
            }

            @Override
            public R textParseUrlIps(String text, List<PlayVo> playVo) {
                log.info("语音转化失败:" + cause.getMessage());
                return R.fail("textParseUrlIps：语音转化失败"+ cause.getMessage());
            }

            @Override
            public R getDeviceList(Integer page, Integer pageSize, Long floorId) {
                log.info("getDeviceList：获取喇叭列表失败:" + cause.getMessage());
                return R.fail("getDeviceList：获取喇叭列表失败"+ cause.getMessage());
            }

            @Override
            public R textParseUrlAppIps(String text, List <PlayVo> playVo) {
                log.info("语音播放失败:" + cause.getMessage());
                return R.fail("textParseUrlIps：语音播放失败"+ cause.getMessage());
            }

            @Override
            public R stopPlayMusic(String text, String ip) {
                log.info("关闭喇叭失败:" + cause.getMessage());
                return R.fail("textParseUrlIps：关闭喇叭失败"+ cause.getMessage());
            }

        };
    }
}
