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

import com.sw.common.accessory.api.model.WarehouseInputBillBo;
import com.sw.common.accessory.api.model.WarehouseOutputBillBo;
import com.sw.common.accessory.api.feignCilent.StoreFeignClients;
import com.sw.common.accessory.server.dto.WarehouseMaterialDto;
import com.sw.common.accessory.server.dto.WarehouseModelDto;
import com.sw.common.accessory.server.dto.WarehouseOutputRecordBillDetailDto;
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;


@Slf4j
@Component
public class StoreFeignClientsFallback implements FallbackFactory<StoreFeignClients> {

    @Override
    public StoreFeignClients create(Throwable throwable) {
        return new StoreFeignClients() {

            @Override
            public Result inputApply(WarehouseInputBillBo inputBillBo) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【线边仓-入库申请】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result outputApply(WarehouseOutputBillBo outputBillBo) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【线边仓-出库申请】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result cancelInputApply(String billNo) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【线边仓-取消入库申请】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result cancelOutputApply(String billNo) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【线边仓-取消出库申请】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<WarehouseMaterialDto> getByStoreMaterialCode(String materialCode) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【根据物料Code查询物料配置】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<WarehouseOutputRecordBillDetailDto> getOutputBillByMaterialCode(String materialCode) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【通过物料编码查询出库记录】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<WarehouseOutputRecordBillDetailDto> getOutputBillByUniqueCode(String uniqueCode) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【通过唯一码查询出库记录】接口失败：" + throwable.getMessage());
            }

            @Override
            public Result<WarehouseModelDto> getCode(String code) {
                return ResultGenerator.fail(ResultCode.ESERVER.getCode(), "调用【线边仓模型详细信息】接口失败：" + throwable.getMessage());
            }
        };
    }
}
