package com.sw.common.accessory.api.fallBackFactory;

import com.sw.common.accessory.api.feignCilent.YbFeignClients;
import com.sw.common.accessory.api.model.AccessoryMaterialDto;
import com.sw.common.accessory.api.model.EquipmentDto;
import com.sw.common.accessory.api.model.MaterialModelDto;
import com.sw.common.accessory.server.dto.*;
import com.sw.common.core.response.Result;
import com.sw.common.core.response.ResultCode;
import com.sw.common.core.response.ResultGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@Component
public class YbFeignClientsFallback implements FallbackFactory<YbFeignClients> {
    @Override
    public YbFeignClients create(Throwable throwable) {
        log.error(throwable.getMessage());
        return new YbFeignClients() {
            @Override
            public Result<AccessoryMaterialDto> getByMaterialCode(String materialCode) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据物料编码:" + materialCode + "查询物料主数据】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<AccessoryMaterialDto> getByMaterialCodes(String materialCode) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据物料编码:" + materialCode + "查询物料主数据】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<AccessoryMaterialDto> getByMaterialId(Long materialId) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据物料ID:" + materialId + "查询物料主数据】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<EquipmentDto> getByCodeDto(String equipmentCode) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据设备编码:" + equipmentCode + "查询物料主数据】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<EquipmentDto> getEquipmentInfo(String equipmentCode) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据设备编码:" + equipmentCode + "查询物料主数据】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result sendSapGoodsmvt(@Valid ReportSapGoodsmvtDto reportSapGoodsmvtDto) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【报工】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result sendSapWorkinghours(ReportSapWorkinghoursDto ReportSapWorkinghoursDto) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【报工工时】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<DictionaryItemDto> findByThemeValueAndNameAndValueAndEnable(String themeValue, String name, String value, boolean enable) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据字段主题和词条名称,词条值查询字典词条】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<DictionaryItemDto> findByThemeCodeAndItemName(String themeValue, String itemName) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据字段主题和词条名称查询字典词条】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result getDeviceId(Long id) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【设备类型根据设备编码获取】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<List<EquipmentDto>> findByDeviceId(Integer deviceId) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据类型id获取所有设备】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<ProductionScheduleDto> findPlanProductionById(Long id) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据任务ID查询工单排程】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<ProductionOrderDto> getListByWorkType(String aufnr) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据计划工单获取计划订单详情】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<ProductionOrderDto> findProductionOrderById(Long id) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【工单详细信息】接口失败：" + throwable.getMessage());
            }
        };
    }
}
