package com.mortals.xhx.feign.holiday;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.holiday.HolidayPdu;
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-10-09
 */
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = HolidayFeignFallbackFactory.class)
public interface IHolidayFeign extends IFeign {


    /**
     * 查看节假日列表
     *
     * @param holidayPdu
     * @return
     */
    @PostMapping(value = "/holiday/interlist")
    Rest<RespData<List<HolidayPdu>>> list(@RequestBody HolidayPdu holidayPdu);


    /**
     * 查看节假日
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/holiday/interinfo")
    Rest<HolidayPdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除节假日
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/holiday/delete")
    Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 节假日保存更新
     *
     * @param holidayPdu
     * @return
     */
    @PostMapping(value = "/holiday/save")
    Rest<RespData<HolidayPdu>> save(@RequestBody HolidayPdu holidayPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class HolidayFeignFallbackFactory implements FallbackFactory<IHolidayFeign> {
    @Override
    public IHolidayFeign create(Throwable t) {
        return new IHolidayFeign() {
            @Override
            public Rest<RespData<List<HolidayPdu>>> list(HolidayPdu holidayPdu) {
               return Rest.fail("暂时无法获取节假日列表，请稍后再试!");
            }

            @Override
            public Rest<HolidayPdu> info(Long id) {
               return Rest.fail("暂时无法获取节假日详细，请稍后再试!");
            }

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

            @Override
            public Rest<RespData<HolidayPdu>> save(HolidayPdu holidayPdu, String authorization) {
                return Rest.fail("暂时无法保存节假日，请稍后再试!");
            }
        };
    }
}








