package com.mortals.xhx.feign.app;

import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.app.AppPdu;
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 = AppFeignFallbackFactory.class)
public interface IAppFeign extends IFeign {


    /**
     * 查看自助终端应用列表
     *
     * @param appPdu
     * @return
     */
    @PostMapping(value = "/app/interlist")
    Rest<RespData<List<AppPdu>>> list(@RequestBody AppPdu appPdu);


    /**
     * 查看自助终端应用
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/app/interinfo")
    Rest<AppPdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除自助终端应用
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/app/delete")
    Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 自助终端应用保存更新
     *
     * @param appPdu
     * @return
     */
    @PostMapping(value = "/app/save")
    Rest<RespData<AppPdu>> save(@RequestBody AppPdu appPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class AppFeignFallbackFactory implements FallbackFactory<IAppFeign> {
    @Override
    public IAppFeign create(Throwable t) {
        return new IAppFeign() {
            @Override
            public Rest<RespData<List<AppPdu>>> list(AppPdu appPdu) {
               return Rest.fail("暂时无法获取自助终端应用列表，请稍后再试!");
            }

            @Override
            public Rest<AppPdu> info(Long id) {
               return Rest.fail("暂时无法获取自助终端应用详细，请稍后再试!");
            }

            @Override
            public Rest<Void> delete(Long[] ids, String authorization) {
                return Rest.fail("暂时无法删除自助终端应用，请稍后再试!");
            }

            @Override
            public Rest<RespData<AppPdu>> save(AppPdu appPdu, String authorization) {
                return Rest.fail("暂时无法保存自助终端应用，请稍后再试!");
            }
        };
    }
}








