package com.hdkj.lt.feign.fallback;

import com.alibaba.fastjson.JSON;
import com.hdkj.lt.modle.dto.psrdevice.JoinEcTransformerDTO;
import com.hdkj.lt.modle.po.JoinEcTransformerPO;
import com.hdkj.lt.feign.IPsrDeviceApiClient;
import com.hdkj.lt.modle.dto.psrdevice.PsrDeviceQueryDTO;
import com.hdkj.lt.modle.vo.psrdevice.PsrDeviceResponseVO;
import com.hdkj.hussar.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description
 * @Author wcx
 * @Date 2025/7/30 10:35
 * @Version 1.0
 */
@Slf4j
@Component
public class PsrDeviceApiClientFallBack implements FallbackFactory<IPsrDeviceApiClient> {
    @Override
    public IPsrDeviceApiClient create(Throwable cause) {
        return new IPsrDeviceApiClient() {
            @Override
            public ApiResponse<PsrDeviceResponseVO> getPsrDeviceByCommonInterface(PsrDeviceQueryDTO psrDeviceQuery) {
                log.error("电网业务中台-设备通用接口远程调用服务异常,参数:{},异常:{}", JSON.toJSONString(psrDeviceQuery), cause.getMessage());
                return ApiResponse.fail(String.format("电网业务中台-设备通用接口远程调用服务异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<List<JoinEcTransformerPO>> getJoinEcTransformerInfo(JoinEcTransformerDTO joinEcTransformer) {
                log.error("电网业务中台-中压用户和专变接口远程调用服务异常,参数:{},异常:{}", JSON.toJSONString(joinEcTransformer), cause.getMessage());
                return ApiResponse.fail(String.format("电网业务中台-中压用户和专变接口远程调用服务异常：%s", cause.getMessage()));
            }
        };
    }
}
