package dev.photosync.core.upload;

/**
 * Where a job is in its life.
 *
 * <p>{@link #FAILED} is neither active nor finished on purpose: the job has run
 * out of automatic attempts and is now waiting for the player to press retry.
 * Treating it as finished would quietly lose screenshots; treating it as active
 * would keep the quit dialog open forever.
 */
public enum UploadState {

    /** Waiting for a free worker. */
    PENDING,
    /** A worker is pushing bytes right now. */
    UPLOADING,
    /** A retryable error; will be picked up again after a backoff. */
    RETRYING,
    /** The backend has the file. */
    COMPLETED,
    /** Out of attempts, or a permanent error. Needs the player. */
    FAILED,
    /** The player removed it before it went up. */
    CANCELLED;

    /** Counts as outstanding work: the quit dialog waits for these. */
    public boolean isActive() {
        return this == PENDING || this == UPLOADING || this == RETRYING;
    }

    /** Nothing more will happen without the player asking. */
    public boolean isFinished() {
        return this == COMPLETED || this == CANCELLED;
    }

    /** Worth writing to the queue file, because it still means something next launch. */
    public boolean isPersistent() {
        return isActive() || this == FAILED;
    }
}
