package org.academiadecodigo.bootcamp.fxlogin.service;

import java.util.Map;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class ServiceRegistry {
    private Map<String, Service> services;

    public ServiceRegistry(Map<String, Service> services) {
        this.services = services;
    }

    @SuppressWarnings("unchecked")
    public <T extends Service> T get(String name) {
        return (T) services.get(name);
    }

    public void add(Service service) {
        if (service == null) {
            throw new IllegalArgumentException();
        }
        services.put(service.getClass().getInterfaces()[0].getSimpleName(), service);
    }

    public void remove(String name) {
        services.remove(name);
    }

    int size() {
        return services.size();
    }

    void clear() {
        services.clear();
    }


}
