package xyz.wbsite.frame.provider;

import xyz.wbsite.frame.base.LocalData;

import java.util.Iterator;
import java.util.Map;

public class FrameProvider {

    private static FrameProvider ourInstance = new FrameProvider();

    public static FrameProvider getInstance() {
        return ourInstance;
    }

    private FrameProvider() {
    }

    public UserProvider getUserProvider() {
        Map<String, UserProvider> beansOfType = LocalData.getApplicationContext().getBeansOfType(UserProvider.class);
        if (beansOfType.size() == 0) {
            return null;
        }
        Iterator<String> iterator = beansOfType.keySet().iterator();
        String name = iterator.next();
        while (iterator.hasNext()) {
            String next = iterator.next();
            name = !"simpleUserProvider".equals(next) ? next : name;
        }
        return beansOfType.get(name);
    }

    public TokenProvider getTokenProvider() {
        Map<String, TokenProvider> beansOfType = LocalData.getApplicationContext().getBeansOfType(TokenProvider.class);
        if (beansOfType.size() == 0) {
            return null;
        }
        Iterator<String> iterator = beansOfType.keySet().iterator();
        String name = iterator.next();
        while (iterator.hasNext()) {
            String next = iterator.next();
            name = !"simpleTokenProvider".equals(next) ? next : name;
        }
        return beansOfType.get(name);
    }

    public ProfileProvider getProfileProvider() {
        Map<String, ProfileProvider> beansOfType = LocalData.getApplicationContext().getBeansOfType(ProfileProvider.class);
        if (beansOfType.size() == 0) {
            return null;
        }
        Iterator<String> iterator = beansOfType.keySet().iterator();
        String name = iterator.next();
        while (iterator.hasNext()) {
            String next = iterator.next();
            name = !"simpleProfileProvider".equals(next) ? next : name;
        }
        return beansOfType.get(name);
    }

    public DictProvider getDictProvider() {
        Map<String, DictProvider> beansOfType = LocalData.getApplicationContext().getBeansOfType(DictProvider.class);
        if (beansOfType.size() == 0) {
            return null;
        }
        Iterator<String> iterator = beansOfType.keySet().iterator();
        String name = iterator.next();
        while (iterator.hasNext()) {
            String next = iterator.next();
            name = !"simpleDictProvider".equals(next) ? next : name;
        }
        return beansOfType.get(name);
    }
}
