package com.mortals.xhx.feign.window;

import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.holiday.HolidayPdu;
import com.mortals.xhx.common.pdu.window.WindowPdu;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 大厅窗口 Feign接口
 */
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = WindowFeignFallbackFactory.class)
public interface IWindowFeign extends IFeign {

    @PostMapping(value = "/window/interlist")
    Rest<RespData<List<WindowPdu>>> list(@RequestBody WindowPdu windowPdu);

    /**
     * 查看站点部门窗口
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/window/interinfo")
    Rest<WindowPdu> info(@RequestParam(value = "id") Long id);

}

@Slf4j
@Component
class WindowFeignFallbackFactory implements FallbackFactory<IWindowFeign> {

    @Override
    public IWindowFeign create(Throwable cause) {
        return new IWindowFeign(){

            @Override
            public Rest<RespData<List<WindowPdu>>> list(WindowPdu windowPdu) {
                return Rest.fail("暂时无法访问窗口列表接口，请稍后再试!");
            }

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

    }
}
