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

import com.xisc.pm.api.dto.PmUpdateSlabDTO;
import com.xisc.pm.domain.vo.MatStatusModifyVO;
import com.xisc.pm.domain.vo.MmAutoHeatPlanVO;
import com.xisc.pm.domain.vo.MmCutSeqVO;
import com.xisc.pm.infra.feign.MmApiFeign;
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/21 10:10
 * @description
 */
@Component
public class MmApiFeignFallbackFactory implements FallbackFactory<MmApiFeign> {
    private static final Logger LOGGER = LoggerFactory.getLogger(MmApiFeignFallbackFactory.class);

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

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

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

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

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

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