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

import com.xisc.pm.api.dto.ProdPonoSlabRequestDTO;
import com.xisc.pm.api.dto.ThickPlatePerformanceDeterminationDTO;
import com.xisc.pm.domain.vo.QeResvReplaceTriggerVO;
import com.xisc.pm.domain.vo.QeSampleAddtionRequestVO;
import com.xisc.pm.domain.vo.SlabNoCorrespondingBigLotVo;
import com.xisc.pm.infra.feign.QeApiFeign;

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/22 17:05
 * @description
 */
@Component
public class QeApiFeignFallbackFactory implements FallbackFactory<QeApiFeign> {
    private static final Logger LOGGER = LoggerFactory.getLogger(QeApiFeignFallbackFactory.class);

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

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

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

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

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

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

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

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