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.SiteHallPdu;
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-04-26
 */
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = SiteHallFeignFallbackFactory.class)
public interface ISiteHallFeign extends IFeign {


    /**
     * 查看站点大厅信息列表
     *
     * @param siteHallPdu
     * @return
     */
    @PostMapping(value = "/site/hall/interlist")
    Rest<RespData<List<SiteHallPdu>>> list(@RequestBody SiteHallPdu siteHallPdu);


    /**
     * 查看站点大厅信息
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/site/hall/interinfo")
    Rest<SiteHallPdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除站点大厅信息
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/site/hall/delete")
    Rest<Void> delete(Long[] ids, @RequestHeader("Authorization") String authorization);


    /**
     * 站点大厅信息保存更新
     *
     * @param siteHallPdu
     * @return
     */
    @PostMapping(value = "/site/hall/save")
    Rest<RespData<SiteHallPdu>> save(@RequestBody SiteHallPdu siteHallPdu, @RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class SiteHallFeignFallbackFactory implements FallbackFactory<ISiteHallFeign> {
    @Override
    public ISiteHallFeign create(Throwable t) {
        return new ISiteHallFeign() {
            @Override
            public Rest<RespData<List<SiteHallPdu>>> list(SiteHallPdu siteHallPdu) {
                return Rest.fail("暂时无法获取站点大厅信息列表，请稍后再试!");
            }

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

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

            @Override
            public Rest<RespData<SiteHallPdu>> save(SiteHallPdu siteHallPdu, String authorization) {
                return Rest.fail("暂时无法保存站点大厅信息，请稍后再试!");
            }
        };
    }
}








