package com.mortals.xhx.feign.sms;

import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.sms.SmsSetPdu;
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-07-28
 */
@FeignClient(name = "base-manager", path = "/base", fallbackFactory = SmsSetFeignFallbackFactory.class)
public interface ISmsSetFeign extends IFeign {


    /**
     * 查看短信设置列表
     *
     * @param smsSetPdu
     * @return
     */
    @PostMapping(value = "/sms/set/interlist")
    Rest<RespData<List<SmsSetPdu>>> list(@RequestBody SmsSetPdu smsSetPdu);


    /**
     * 查看短信设置
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/sms/set/interinfo")
    Rest<SmsSetPdu> info(@RequestParam(value = "id") Long id);

    /**
     * 删除短信设置
     *
     * @param ids
     * @return
     */
    @GetMapping(value = "/sms/set/delete")
    Rest<Void> delete(Long[] ids,@RequestHeader("Authorization") String authorization);


    /**
     * 短信设置保存更新
     *
     * @param smsSetPdu
     * @return
     */
    @PostMapping(value = "/sms/set/save")
    Rest<RespData<SmsSetPdu>> save(@RequestBody SmsSetPdu smsSetPdu,@RequestHeader("Authorization") String authorization);


}


@Slf4j
@Component
class SmsSetFeignFallbackFactory implements FallbackFactory<ISmsSetFeign> {
    @Override
    public ISmsSetFeign create(Throwable t) {
        return new ISmsSetFeign() {
            @Override
            public Rest<RespData<List<SmsSetPdu>>> list(SmsSetPdu smsSetPdu) {
               return Rest.fail("暂时无法获取短信设置列表，请稍后再试!");
            }

            @Override
            public Rest<SmsSetPdu> info(Long id) {
               return Rest.fail("暂时无法获取短信设置详细，请稍后再试!");
            }

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

            @Override
            public Rest<RespData<SmsSetPdu>> save(SmsSetPdu smsSetPdu, String authorization) {
                return Rest.fail("暂时无法保存短信设置，请稍后再试!");
            }
        };
    }
}








