package com.mortals.xhx.feign.site;

import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.site.SiteMatterPdu;
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-02-17
 */
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = SiteMatterFeignFallbackFactory.class)
public interface ISiteMatterFeign extends IFeign {


    /**
     * 查看站点事项列表
     *
     * @param siteMatterPdu
     * @return
     */
    @PostMapping(value = "/site/matter/list")
    Rest<RespData<List<SiteMatterPdu>>> list(@RequestBody SiteMatterPdu siteMatterPdu);


    /**
     * 查看站点事项
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/site/matter/info")
    Rest<SiteMatterPdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除站点事项
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/site/matter/delete")
    Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 站点事项保存更新
     *
     * @param siteMatterPdu
     * @return
     */
    @PostMapping(value = "/site/matter/save")
    Rest<RespData<SiteMatterPdu>> save(@RequestBody SiteMatterPdu siteMatterPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class SiteMatterFeignFallbackFactory implements FallbackFactory<ISiteMatterFeign> {
    @Override
    public ISiteMatterFeign create(Throwable t) {
        return new ISiteMatterFeign() {
            @Override
            public Rest<RespData<List<SiteMatterPdu>>> list(SiteMatterPdu siteMatterPdu) {
               return Rest.fail("暂时无法获取站点事项列表，请稍后再试!");
            }

            @Override
            public Rest<SiteMatterPdu> info(Long id) {
               return Rest.fail("暂时无法获取站点事项详细，请稍后再试!");
            }

            @Override
            public Rest<Void> delete(Long[] ids, String authorization) {
                return Rest.fail("暂时无法删除站点事项，请稍后再试!");
            }

            @Override
            public Rest<RespData<SiteMatterPdu>> save(SiteMatterPdu siteMatterPdu, String authorization) {
                return Rest.fail("暂时无法保存站点事项，请稍后再试!");
            }
        };
    }
}








