package cn.sagacloud.server.scheduler.pojo

/*
 * Author: Jxing
 * Create Time: 2019/3/11
 */

import java.util.ArrayList
import java.util.Arrays

enum class TaskStatus {
    // 顺序不可打乱, 添加要在后面添加
    Waiting,
    Sending, Sent, FileDownloadException, CommandExecuteException, Finished;


    companion object {
        private var statusList: ArrayList<TaskStatus>? = null

        init {
            statusList = ArrayList()
            statusList!!.addAll(Arrays.asList(*TaskStatus.values()))
        }

        fun getTaskStatusById(index: Int?): TaskStatus? {
            if(index == null)
                return null
            return if (index > -1 && index < statusList!!.size) {
                statusList!![index]
            } else null
        }

        fun getIdByTaskStatus(status: TaskStatus?): Int {
            if (status == null)
                return -1
            for (i in statusList!!.indices) {
                if (statusList!![i] == status)
                    return i
            }
            return -1
        }
    }
}
