package com.mortals.xhx.feign.firm;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.firm.FirmPdu;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.feign.IFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * 设备生产厂商 Feign接口
 * @author zxfei
 * @date 2023-06-21
 */
@FeignClient(name = "device-manager", path = "/m", fallbackFactory = FirmFeignFallbackFactory.class)
public interface IFirmFeign extends IFeign {


    /**
     * 查看设备生产厂商列表
     *
     * @param firmPdu
     * @return
     */
    @PostMapping(value = "/firm/list")
    Rest<RespData<List<FirmPdu>>> list(@RequestBody FirmPdu firmPdu);


    /**
     * 查看设备生产厂商
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/firm/info")
    Rest<FirmPdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除设备生产厂商
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/firm/delete")
    Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 设备生产厂商保存更新
     *
     * @param firmPdu
     * @return
     */
    @PostMapping(value = "/firm/save")
    Rest<RespData<FirmPdu>> save(@RequestBody FirmPdu firmPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class FirmFeignFallbackFactory implements FallbackFactory<IFirmFeign> {
    @Override
    public IFirmFeign create(Throwable t) {
        return new IFirmFeign() {
            @Override
            public Rest<RespData<List<FirmPdu>>> list(FirmPdu firmPdu) {
               return Rest.fail("暂时无法获取设备生产厂商列表，请稍后再试!");
            }

            @Override
            public Rest<FirmPdu> info(Long id) {
               return Rest.fail("暂时无法获取设备生产厂商详细，请稍后再试!");
            }

            @Override
            public Rest<Void> delete(Long[] ids, String authorization) {
                return Rest.fail("暂时无法删除设备生产厂商，请稍后再试!");
            }

            @Override
            public Rest<RespData<FirmPdu>> save(FirmPdu firmPdu, String authorization) {
                return Rest.fail("暂时无法保存设备生产厂商，请稍后再试!");
            }
        };
    }
}








