package ch.unisg.roster.roster.domain;

import ch.unisg.common.valueobject.ExecutorURI;
import ch.unisg.roster.roster.domain.valueobject.ExecutorType;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import static org.assertj.core.api.Assertions.*;


public class RosterTest {

    @Test
    void addAssignmentToRosterMapTest(){
        Roster roster = Roster.getInstance();
        Collection<RosterItem> rosterMap = roster.getRosterMap();
        rosterMap.clear();
        Collection<ArrayList<Task>> queues = roster.getAllTasksFromQueue();
        queues.clear();
        roster.addTaskToQueue(new Task("TEST-ID", "TEST-TYPE"));
        Task task = roster.assignTaskToExecutor(new ExecutorType("TEST-TYPE"), new ExecutorURI("TEST-URI"));

        assertThat(rosterMap.size()).isEqualTo(1);
        assertThat(rosterMap.iterator().next().getTaskID()).isEqualTo("TEST-ID");
        assertThat(rosterMap.iterator().next().getTaskType()).isEqualTo("TEST-TYPE");
        assertThat(rosterMap.iterator().next().getExecutorURI().getValue().toString()).isEqualTo("TEST-URI");

        assertThat(task.getTaskType().getValue().toString()).isEqualTo("TEST-TYPE");
        assertThat(task.getTaskID()).isEqualTo("TEST-ID");

        boolean empty_queue = roster.deleteTask("TEST-ID", new ExecutorType("TEST-TYPE"));
        // TODO test that the task was removed from the Queue similar to below --> I don't know if it actually gets deleted or not
        //assertThat(empty_queue).isEqualTo(true);
        //assertThat(queues.size()).isEqualTo(0);
    }

    @Test
    void removeTaskFromQueue(){
        Roster roster = Roster.getInstance();
        Collection<ArrayList<Task>> queues = roster.getAllTasksFromQueue();
        queues.clear();
        roster.addTaskToQueue(new Task("TEST-ID", "TEST-TYPE"));

        boolean test = roster.deleteTask("TEST-ID", new ExecutorType("TEST-TYPE"));

        assertThat(test).isEqualTo(true);
        assertThat(queues.size()).isEqualTo(1);
    }
}
