package com.atlassian.confluence.extra.workflow.model;

import com.atlassian.confluence.extra.workflow.WorkflowClient;
import com.atlassian.confluence.extra.workflow.ConfluencePageWorkflowClient;
import com.atlassian.confluence.extra.workflow.State;
import com.atlassian.user.User;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: Tomd
 * Date: 10/05/2005
 * Time: 11:04:54
 * To change this template use File | Settings | File Templates.
 */
public class WorkflowTasksModel
{
    private Map tasks = new HashMap();

    public void add(WorkflowClient client, User user)
    {
        List tasksInState = (List) tasks.get(client.getState());
        if (tasksInState == null)
        {
            tasksInState = new ArrayList();
            tasks.put(client.getState(),tasksInState);
        }
        ConfluencePageWorkflowClient cpwfc = (ConfluencePageWorkflowClient) client;
        tasksInState.add(new WorkflowTaskModel(cpwfc.getContentEntityObject(),!client.getType().getAvailableOperations(client,user).isEmpty()));
    }

    public Set getStates()
    {
        return tasks.keySet();
    }

    public List getTasksForState(State state)
    {
        Object o = tasks.get(state);
        return (List) o;
    }
}
