package com.social.media.domain.bot.valueobject;

/**
 * Enumeration of bot execution status
 */
public enum ExecutionStatus {
    PENDING("PENDENTE", false, false),
    RUNNING("EXECUTANDO", true, false),
    COMPLETED("CONCLUIDO", false, true),
    FAILED("FALHOU", false, true),
    CANCELLED("CANCELADO", false, true),
    PAUSED("PAUSADO", false, false),
    RETRYING("TENTANDO_NOVAMENTE", true, false);
    
    private final String dbValue;
    private final boolean isActive;
    private final boolean isTerminal;
    
    ExecutionStatus(String dbValue, boolean isActive, boolean isTerminal) {
        this.dbValue = dbValue;
        this.isActive = isActive;
        this.isTerminal = isTerminal;
    }
    
    public String getDbValue() {
        return dbValue;
    }
    
    public boolean isActive() {
        return isActive;
    }
    
    public boolean isTerminal() {
        return isTerminal;
    }
    
    public boolean canBeCancelled() {
        return this == PENDING || this == RUNNING || this == PAUSED;
    }
    
    public boolean canBePaused() {
        return this == RUNNING;
    }
    
    public boolean canBeResumed() {
        return this == PAUSED;
    }
    
    public boolean canBeRetried() {
        return this == FAILED;
    }
    
    public boolean canBeRestarted() {
        return this == COMPLETED || this == FAILED || this == CANCELLED;
    }
    
    public boolean isInProgress() {
        return this == RUNNING || this == RETRYING;
    }
    
    public boolean hasError() {
        return this == FAILED;
    }
    
    public boolean isSuccessful() {
        return this == COMPLETED;
    }
    
    public static ExecutionStatus fromDbValue(String dbValue) {
        for (ExecutionStatus status : values()) {
            if (status.dbValue.equals(dbValue)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown execution status: " + dbValue);
    }
}
