package com.social.media.domain.bot.valueobject;

/**
 * Enumeration of bot execution status
 */
public enum BotStatus {
    ACTIVE("ATIVO", true, false),
    INACTIVE("INATIVO", false, false),
    RUNNING("EXECUTANDO", true, true),
    PAUSED("PAUSADO", false, true),
    ERROR("ERRO", false, false),
    COMPLETED("CONCLUIDO", false, false),
    CANCELLED("CANCELADO", false, false);
    
    private final String dbValue;
    private final boolean canExecute;
    private final boolean isInExecution;
    
    BotStatus(String dbValue, boolean canExecute, boolean isInExecution) {
        this.dbValue = dbValue;
        this.canExecute = canExecute;
        this.isInExecution = isInExecution;
    }
    
    public String getDbValue() {
        return dbValue;
    }
    
    public boolean canExecute() {
        return canExecute;
    }
    
    public boolean isInExecution() {
        return isInExecution;
    }
    
    public boolean canBeStarted() {
        return this == ACTIVE || this == PAUSED || this == ERROR;
    }
    
    public boolean canBePaused() {
        return this == RUNNING;
    }
    
    public boolean canBeStopped() {
        return this == RUNNING || this == PAUSED;
    }
    
    public boolean canBeActivated() {
        return this == INACTIVE || this == ERROR || this == COMPLETED;
    }
    
    public boolean canBeDeactivated() {
        return this == ACTIVE || this == PAUSED;
    }
    
    public boolean canBeEdited() {
        return this == ACTIVE || this == INACTIVE || this == PAUSED || this == ERROR;
    }
    
    public boolean canBeDeleted() {
        return this != RUNNING;
    }
    
    public boolean hasError() {
        return this == ERROR;
    }
    
    public boolean isTerminal() {
        return this == COMPLETED || this == CANCELLED;
    }
    
    public static BotStatus fromDbValue(String dbValue) {
        for (BotStatus status : values()) {
            if (status.dbValue.equals(dbValue)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown bot status: " + dbValue);
    }
}
