package com.xisc.pm.infra.feign.fallback;

import com.xisc.pm.domain.vo.WmInStockVO;
import com.xisc.pm.domain.vo.WmSigleQtyVO;
import com.xisc.pm.infra.feign.WmApiFeign;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @date 2024/10/23 11:47
 * @description
 */
@Component
public class WmApiFeignFallbackFactory implements FallbackFactory<WmApiFeign> {
    private static final Logger LOGGER = LoggerFactory.getLogger(WmApiFeignFallbackFactory.class);
    public WmApiFeign create(Throwable cause) {
        return new WmApiFeign() {
            @Override
            public ResponseEntity<String> syncSigleQty(Long organizationId, List<WmSigleQtyVO> WmSigleQtyVOs) {
                // 记录异常堆栈跟踪信息以进行故障排除
                LOGGER.error("syncSigleQty-error: {}", ExceptionUtils.getStackTrace(cause));
                // 返回HTTP 500状态码表示服务器错误
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
            }

            @Override
            public ResponseEntity<String> matRemove(Long tenantId, List<WmInStockVO> wmInStockVOS) {
                // 记录异常堆栈跟踪信息以进行故障排除
                LOGGER.error("matRemove-error: {}", ExceptionUtils.getStackTrace(cause));
                // 返回HTTP 500状态码表示服务器错误
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
            }

            @Override
            public ResponseEntity<String> inStock(Long tenantId, List<WmInStockVO> wmInStockVOS) {
                // 记录异常堆栈跟踪信息以进行故障排除
                LOGGER.error("inStock-error: {}", ExceptionUtils.getStackTrace(cause));
                // 返回HTTP 500状态码表示服务器错误
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
            }
        };
    }
}
