package com.pj.sms.factory;


import com.pj.current.config.MyConfig;
import com.pj.current.config.SystemObject;
import com.pj.sms.handler.ISmsHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SmsFactory {
    @Resource
    private MyConfig myConfig;
    @Autowired
    private List<ISmsHandler> handlers;

    public ISmsHandler handler() {
        String type= SystemObject.config.getSmsType();
        return handlers.stream().filter(h -> h.smsType().getType().equals(type))
                .findAny().orElseThrow(() -> new IllegalArgumentException("不支持类型短信发送：" + type));
    }

}
