package com.social.media.domain.content.valueobject;

/**
 * Enumeration of post status in the publishing workflow
 */
public enum PostStatus {
    DRAFT("RASCUNHO", false, false),
    SCHEDULED("AGENDADO", true, false),
    PUBLISHING("PUBLICANDO", true, false),
    PUBLISHED("PUBLICADO", true, true),
    ERROR("ERRO", false, false),
    FAILED("FALHA", false, false),
    ARCHIVED("ARQUIVADO", false, false),
    CANCELLED("CANCELADO", false, false);
    
    private final String dbValue;
    private final boolean canBePublished;
    private final boolean isPublished;
    
    PostStatus(String dbValue, boolean canBePublished, boolean isPublished) {
        this.dbValue = dbValue;
        this.canBePublished = canBePublished;
        this.isPublished = isPublished;
    }
    
    public String getDbValue() {
        return dbValue;
    }
    
    public boolean canBePublished() {
        return canBePublished;
    }
    
    public boolean isPublished() {
        return isPublished;
    }
    
    public boolean canBeEdited() {
        return this == DRAFT || this == SCHEDULED || this == ERROR;
    }
    
    public boolean canBeDeleted() {
        return this != PUBLISHING;
    }
    
    public boolean canBeScheduled() {
        return this == DRAFT;
    }
    
    public boolean canBeCancelled() {
        return this == SCHEDULED;
    }
    
    public boolean isInProgress() {
        return this == PUBLISHING;
    }
    
    public boolean hasError() {
        return this == ERROR;
    }
    
    public boolean isFinal() {
        return this == PUBLISHED || this == CANCELLED;
    }
    
    public boolean isDraft() {
        return this == DRAFT;
    }
    
    public boolean isScheduled() {
        return this == SCHEDULED;
    }
    
    public boolean isFailed() {
        return this == FAILED || this == ERROR;
    }
    
    public boolean isArchived() {
        return this == ARCHIVED;
    }
    
    public static PostStatus fromDbValue(String dbValue) {
        for (PostStatus status : values()) {
            if (status.dbValue.equals(dbValue)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown post status: " + dbValue);
    }
}
