package org.academiadecodigo.bootcamp.service.bootcamp;

import org.academiadecodigo.bootcamp.model.Bootcamp;
import org.academiadecodigo.bootcamp.model.CodeCadet;

import java.util.*;

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

public class MockBootcampService implements BootcampService {
    private Map<Integer, Bootcamp> bootcamps;
    private Integer selectedBootcamp;

    public MockBootcampService() {
        this.bootcamps = new HashMap<>();
    }

    @Override
    public void createBootcamp(Integer id, Bootcamp.BootcampLocation location, String start, String end) {
        if (bootcamps.containsKey(id)) {
            return;
        }

        bootcamps.put(id, new Bootcamp(id, location, start, end));
    }

    @Override
    public void addCodeCadet(Integer bootcampId, CodeCadet codeCadet) {
        if (!bootcamps.containsKey(bootcampId)) {
            return;
        }

        if (bootcamps.get(bootcampId).contains(codeCadet)) {
            return;
        }

        bootcamps.get(bootcampId).addCodeCadet(codeCadet);
    }

    @Override
    public void addCodeCadets(Integer bootcampId, CodeCadet... codeCadets) {
        if (!bootcamps.containsKey(bootcampId)) {
            return;
        }

        Bootcamp bootcampToAddTo = bootcamps.get(bootcampId);
        for (CodeCadet cadet : codeCadets) {
            bootcampToAddTo.addCodeCadet(cadet);
        }
    }

    @Override
    public List<Bootcamp> listBootcamps() {
        return new LinkedList<>(bootcamps.values());
    }

    @Override
    public Set<CodeCadet> listCodeCadets(Integer bootcampId) {
        return bootcamps.get(bootcampId).getCadets();
    }

    @Override
    public void setSelectedBootcamp(Integer bootcampId) {
        this.selectedBootcamp = bootcampId;
    }

    @Override
    public Integer getSelectedBootcamp() {
        return selectedBootcamp;
    }

}
