package com.mortals.xhx.feign.skin;

import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.skin.SkinBasePdu;
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 2022-08-01
 */
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = SkinBaseFeignFallbackFactory.class)
public interface ISkinBaseFeign extends IFeign {


    /**
     * 查看系统基础皮肤列表
     *
     * @param skinBasePdu
     * @return
     */
    @PostMapping(value = "/skin/base/interlist")
    Rest<RespData<List<SkinBasePdu>>> list(@RequestBody SkinBasePdu skinBasePdu);


    /**
     * 查看系统基础皮肤
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/skin/base/interinfo")
    Rest<SkinBasePdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除系统基础皮肤
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/skin/base/delete")
    Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 系统基础皮肤保存更新
     *
     * @param skinBasePdu
     * @return
     */
    @PostMapping(value = "/skin/base/save")
    Rest<RespData<SkinBasePdu>> save(@RequestBody SkinBasePdu skinBasePdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class SkinBaseFeignFallbackFactory implements FallbackFactory<ISkinBaseFeign> {
    @Override
    public ISkinBaseFeign create(Throwable t) {
        return new ISkinBaseFeign() {
            @Override
            public Rest<RespData<List<SkinBasePdu>>> list(SkinBasePdu skinBasePdu) {
               return Rest.fail("暂时无法获取系统基础皮肤列表，请稍后再试!");
            }

            @Override
            public Rest<SkinBasePdu> info(Long id) {
               return Rest.fail("暂时无法获取系统基础皮肤详细，请稍后再试!");
            }

            @Override
            public Rest<Void> delete(Long[] ids, String authorization) {
                return Rest.fail("暂时无法删除系统基础皮肤，请稍后再试!");
            }

            @Override
            public Rest<RespData<SkinBasePdu>> save(SkinBasePdu skinBasePdu, String authorization) {
                return Rest.fail("暂时无法保存系统基础皮肤，请稍后再试!");
            }
        };
    }
}








