package br.net.venson;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class ShuffleIterator implements PlaylistIterator {
    private List<Song> shuffled;
    private int index = 0;

    public ShuffleIterator(List<Song> songs) {
        this.shuffled = new ArrayList<>(songs);
        Collections.shuffle(this.shuffled);
    }

    public boolean hasNext() {
        return index < shuffled.size();
    }

    public Song next() {
        index = (index + 1) % shuffled.size();
        return shuffled.get(index);
    }

    public boolean hasPrevious() {
        return index >= 0 && index < shuffled.size();
    }

    public Song previous() {
        index = (index - 1 + shuffled.size()) % shuffled.size();
        return shuffled.get(index);
    }

    public Song current() {
        return shuffled.get(index);
    }

    public Song first() {
        index = 0;
        return shuffled.get(index);
    }
    
}