package com.sjyt.icom.asst.conf.fallback;

import com.github.lianjiatech.retrofit.spring.boot.degrade.FallbackFactory;
import com.sjyt.icom.asst.common.enums.ErrorCodeEnum;
import com.sjyt.icom.asst.common.model.sdp.AnswerDto;
import com.sjyt.icom.asst.common.model.sdp.OfferDTO;
import com.sjyt.icom.asst.service.httpapi.SrsHttpApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * <p>SrsHttpApi熔断</p>
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/21 15:48
 */
@Slf4j
@Component
public class SrsHttpDegradeFallbackFactory implements FallbackFactory<SrsHttpApi> {

    @Override
    public SrsHttpApi create(Throwable cause) {
        log.error("SrsHttpApi,熔断触发",cause.getMessage(),cause);
        return new SrsHttpApi() {
            @Override
            public AnswerDto publish(OfferDTO offerDto) {
                AnswerDto answerDto=new AnswerDto();
                answerDto.setCode(Integer.getInteger(ErrorCodeEnum.UNKNOWN_ERROR.getCode()));
                return answerDto;
            }

            @Override
            public AnswerDto pull(OfferDTO offerDto) {
                AnswerDto answerDto=new AnswerDto();
                answerDto.setCode(Integer.getInteger(ErrorCodeEnum.UNKNOWN_ERROR.getCode()));
                return answerDto;
            }
        };
    }
}
