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

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.estate.api.dto.ParkingSpaceDto;
import com.sptg.estate.api.entity.ParkingSpace;
import com.sptg.estate.api.feigns.ParkingSpaceFeign;
import com.sptg.estate.api.feigns.ParkingSpaceFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ParkingSpaceFeignFallbackFactory implements FallbackFactory<ParkingSpaceFeign> {
    @Override
    public ParkingSpaceFeign create(Throwable cause) {
        return new ParkingSpaceFeign() {
            @Override
            public ResultBean<Page<ParkingSpace>> page(ParkingSpaceDto dto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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

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

            @Override
            public ResultBean<Boolean> edit(ParkingSpaceDto dto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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