package com.mortals.xhx.feign.skin;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.skin.SkinFieldPdu;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
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-12-12
 */
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = SkinFieldFeignFallbackFactory.class)
public interface ISkinFieldFeign extends IFeign {


    /**
     * 查看皮肤属性字段配置列表
     *
     * @param skinFieldPdu
     * @return
     */
    @PostMapping(value = "/skin/field/interlist")
    Rest<RespData<List<SkinFieldPdu>>> list(@RequestBody SkinFieldPdu skinFieldPdu);


    /**
     * 查看皮肤属性字段配置
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/skin/field/interinfo")
    Rest<SkinFieldPdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除皮肤属性字段配置
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/skin/field/delete")
    Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 皮肤属性字段配置保存更新
     *
     * @param skinFieldPdu
     * @return
     */
    @PostMapping(value = "/skin/field/save")
    Rest<RespData<SkinFieldPdu>> save(@RequestBody SkinFieldPdu skinFieldPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class SkinFieldFeignFallbackFactory implements FallbackFactory<ISkinFieldFeign> {
    @Override
    public ISkinFieldFeign create(Throwable t) {
        return new ISkinFieldFeign() {
            @Override
            public Rest<RespData<List<SkinFieldPdu>>> list(SkinFieldPdu skinFieldPdu) {
               return Rest.fail("暂时无法获取皮肤属性字段配置列表，请稍后再试!");
            }

            @Override
            public Rest<SkinFieldPdu> info(Long id) {
               return Rest.fail("暂时无法获取皮肤属性字段配置详细，请稍后再试!");
            }

            @Override
            public Rest<Void> delete(Long[] ids, String authorization) {
                return Rest.fail("暂时无法删除皮肤属性字段配置，请稍后再试!");
            }

            @Override
            public Rest<RespData<SkinFieldPdu>> save(SkinFieldPdu skinFieldPdu, String authorization) {
                return Rest.fail("暂时无法保存皮肤属性字段配置，请稍后再试!");
            }
        };
    }
}








