package com.sptg.device.api.feigns.fallback;


import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.device.api.entity.Device;
import com.sptg.device.api.entity.FlowCardDevice;
import com.sptg.device.api.feigns.FlowCardDeviceFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class FlowCardDeviceFeignFallbackFactory implements FallbackFactory<FlowCardDeviceFeign> {

    @Override
    public FlowCardDeviceFeign create(Throwable cause){
        return new FlowCardDeviceFeign() {

            @Override
            public List<FlowCardDevice> getList(FlowCardDevice flowCardDevice) {
                log.error(cause.getMessage(),cause);
                return new ArrayList<>(OperationConstant.ZERO);
            }

            @Override
            public ResultBean<Boolean> add(FlowCardDevice flowCardDevice) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> delete(FlowCardDevice flowCardDevice) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public FlowCardDevice getOne(FlowCardDevice flowCardDevice) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public FlowCardDevice selectOneById(Long id) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public ResultBean<Device> getDeviceByCardId(FlowCardDevice flowCardDevice) {
                return null;
            }
        };
    }

}
