package io.renren.common.advert;

import io.renren.modules.demo.service.RemoteAdvertPort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Set;

@Component
public class AdvertPlatformOauthContext {
    private Map<String, RemoteAdvertPort> advertOauthPortMap;

    @Autowired
    public AdvertPlatformOauthContext(Map<String, RemoteAdvertPort> advertOauthPortMap) {
        this.advertOauthPortMap = advertOauthPortMap;
    }
    public RemoteAdvertPort getAdvertOauthPortByAnnotation(String key) {
        Set<Map.Entry<String, RemoteAdvertPort>> entries = advertOauthPortMap.entrySet();
        for (Map.Entry<String, RemoteAdvertPort> map : entries) {
            RemoteAdvertPort advertOauthPort = map.getValue();
            String value = advertOauthPort.getClass().getAnnotation(AdvertPlatformOauth.class).value();
            if (key.equalsIgnoreCase(value)) {
                return advertOauthPort;
            }
        }
        return advertOauthPortMap.get(AdvertService.SERVICE_OAUTH + AdvertPlatform.OCEANENGINE);
    }


}
