package org.takiguchi.cerberus.cerberusapp.service.servicemanager;

import org.springframework.stereotype.Service;
import org.takiguchi.cerberus.cerberusapp.model.Application;
import org.takiguchi.cerberus.cerberusapp.model.ServiceStatus;

import java.util.*;

import static org.takiguchi.cerberus.cerberusapp.model.ServiceStatus.*;

@Service
public class FakeServiceManager implements ServiceManager {
    private final Map<UUID, ServiceStatus> handledApplications = new HashMap<>();

    @Override
    public ServiceStatus getStatus(Application application) {
        return handledApplications.entrySet()
                .stream()
                .filter(entry -> entry.getKey().equals(application.getId()))
                .findFirst()
                .map(Map.Entry::getValue)
                .orElse(STOPPED);
    }

    @Override
    public void start(Application application) {
        handledApplications.put(application.getId(), STARTED);
    }

    @Override
    public void stop(Application application) {
        handledApplications.put(application.getId(), STOPPED);
    }

    @Override
    public void restart(Application application) {
        start(application);
    }
}
