package org.academiadecodigo.enuminatti.helloworldspringmvc.services;

import org.academiadecodigo.enuminatti.helloworldspringmvc.models.Bootcamp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

public class MockBootcampService implements BootcampService {

    private Map<Integer, Bootcamp> bootcamps;

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

    @Override
    public void addBootcamp(Bootcamp bootcamp) {
        bootcamps.putIfAbsent(bootcamp.getId(), bootcamp);
    }

    @Override
    public void editBootcamp(Bootcamp bootcamp) {
        bootcamps.put(bootcamp.getId(), bootcamp);
    }

    @Override
    public Bootcamp getById(Integer bootcampId) {
        return bootcamps.get(bootcampId);
    }

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

    @Override
    public Long count() {
        return (long) bootcamps.size();
    }

    @Override
    public void remove(Integer id) {
        bootcamps.remove(id);
    }
}
