/*
 * Copyright 2018 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jbpm.workbench.ht.client.util;

import java.util.List;
import java.util.stream.Collectors;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.jbpm.workbench.ht.util.TaskStatus;

import static org.jbpm.workbench.ht.util.TaskStatus.*;

public class TaskUtils {

    public static List<TaskStatus> getTaskStatusByType(TaskType type) {
        ImmutableList<TaskStatus> status = null;
        switch (type) {
            case ACTIVE:
                status = ImmutableList.of(TASK_STATUS_READY,
                                          TASK_STATUS_RESERVED,
                                          TASK_STATUS_IN_PROGRESS);
                break;
            case GROUP:
                status = ImmutableList.of(TASK_STATUS_READY);
                break;
            case ALL:
                status = ImmutableList.of(TASK_STATUS_CREATED,
                                          TASK_STATUS_READY,
                                          TASK_STATUS_RESERVED,
                                          TASK_STATUS_IN_PROGRESS,
                                          TASK_STATUS_SUSPENDED,
                                          TASK_STATUS_FAILED,
                                          TASK_STATUS_ERROR,
                                          TASK_STATUS_EXITED,
                                          TASK_STATUS_OBSOLETE,
                                          TASK_STATUS_COMPLETED);
                break;
            case PERSONAL:
                status = ImmutableList.of(TASK_STATUS_IN_PROGRESS,
                                          TASK_STATUS_CREATED,
                                          TASK_STATUS_RESERVED);
                break;
            case ADMIN:
                status = ImmutableList.of(TASK_STATUS_READY,
                                          TASK_STATUS_IN_PROGRESS,
                                          TASK_STATUS_CREATED,
                                          TASK_STATUS_RESERVED,
                                          TASK_STATUS_SUSPENDED);
                break;
            default:
                throw new IllegalStateException("Unrecognized view type '" + type + "'!");
        }
        return Lists.newArrayList(status);
    }

    public static List<String> getStatusByType(TaskType type) {
        return getTaskStatusByType(type).stream().map(s -> s.getIdentifier()).collect(Collectors.toList());
    }

    public enum TaskType {
        PERSONAL,
        ACTIVE,
        GROUP,
        ALL,
        ADMIN
    }
}
