package com.tzld.piaoquan.ad.engine.commons.feign.longvideo.abtest.fallback;

import com.alibaba.fastjson.JSONObject;
import com.tzld.piaoquan.ad.engine.commons.feign.CommonResponse;
import com.tzld.piaoquan.ad.engine.commons.feign.longvideo.abtest.LongVideoFeign;
import com.tzld.piaoquan.ad.engine.commons.feign.longvideo.abtest.request.AbTestConfigRequest;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

@Service
public class LongVideoFeignFallbackFactory implements FallbackFactory<LongVideoFeignFallback> {
    @Override
    public LongVideoFeignFallback create(Throwable cause) {
        return new LongVideoFeignFallback(cause);
    }
}

class LongVideoFeignFallback implements LongVideoFeign {
    private final Throwable th;

    LongVideoFeignFallback(Throwable th) {
        this.th = th;
    }

    @Override
    public CommonResponse<JSONObject> getAbTestConfig(@RequestBody AbTestConfigRequest request) {
        CommonResponse<JSONObject> response = new CommonResponse<>();
        response.setMsg(th.getMessage());
        response.setCode(1002);


        return response;
    }
}