package com.social.media.domain.shared.enums;

/**
 * Enumeration of user statuses in the system.
 * 
 * This enum defines the possible states a user can be in throughout their lifecycle
 * in the Social Media Manager platform.
 * 
 * @author Social Media Manager Team
 * @version 2.0
 * @since 2025-01-01
 */
public enum UserStatus {
    
    /**
     * User account has been created but not yet verified.
     * User cannot access the system until email verification is complete.
     */
    PENDING("Pending Verification", "Account created, awaiting email verification"),
    
    /**
     * User account is active and fully functional.
     * User has full access to system features based on their permissions.
     */
    ACTIVE("Active", "Account is active and functional"),
    
    /**
     * User account is temporarily inactive.
     * User cannot login but account data is preserved.
     */
    INACTIVE("Inactive", "Account is temporarily inactive"),
    
    /**
     * User account has been suspended due to policy violations.
     * User cannot login and access is restricted pending review.
     */
    SUSPENDED("Suspended", "Account is suspended due to policy violations"),
    
    /**
     * User account has been permanently blocked.
     * User cannot login and account access is permanently restricted.
     */
    BLOCKED("Blocked", "Account is permanently blocked");
    
    private final String displayName;
    private final String description;
    
    UserStatus(String displayName, String description) {
        this.displayName = displayName;
        this.description = description;
    }
    
    /**
     * Gets the human-readable display name of the status.
     * 
     * @return the display name
     */
    public String getDisplayName() {
        return displayName;
    }
    
    /**
     * Gets the description of what this status means.
     * 
     * @return the description
     */
    public String getDescription() {
        return description;
    }
    
    /**
     * Checks if the user can login with this status.
     * 
     * @return true if the user can login
     */
    public boolean canLogin() {
        return this == ACTIVE;
    }
    
    /**
     * Checks if the user can access system features with this status.
     * 
     * @return true if the user can access features
     */
    public boolean canAccessFeatures() {
        return this == ACTIVE;
    }
    
    /**
     * Checks if the user account needs attention (verification, review, etc.).
     * 
     * @return true if the account needs attention
     */
    public boolean needsAttention() {
        return this == PENDING || this == SUSPENDED || this == BLOCKED;
    }
    
    /**
     * Gets the next logical status transitions from the current status.
     * 
     * @return array of possible next statuses
     */
    public UserStatus[] getPossibleTransitions() {
        return switch (this) {
            case PENDING -> new UserStatus[]{ACTIVE, SUSPENDED, BLOCKED};
            case ACTIVE -> new UserStatus[]{INACTIVE, SUSPENDED, BLOCKED};
            case INACTIVE -> new UserStatus[]{ACTIVE, SUSPENDED, BLOCKED};
            case SUSPENDED -> new UserStatus[]{ACTIVE, INACTIVE, BLOCKED};
            case BLOCKED -> new UserStatus[]{}; // No transitions from blocked
        };
    }
    
    /**
     * Checks if transition to the target status is allowed.
     * 
     * @param targetStatus the status to transition to
     * @return true if the transition is allowed
     */
    public boolean canTransitionTo(UserStatus targetStatus) {
        if (targetStatus == null || targetStatus == this) {
            return false;
        }
        
        UserStatus[] allowedTransitions = getPossibleTransitions();
        for (UserStatus allowed : allowedTransitions) {
            if (allowed == targetStatus) {
                return true;
            }
        }
        
        return false;
    }
    
    /**
     * Checks if the user can be activated from this status.
     * 
     * @return true if the user can be activated
     */
    public boolean canBeActivated() {
        return this == PENDING || this == INACTIVE || this == SUSPENDED;
    }
    
    /**
     * Checks if the user can be suspended from this status.
     * 
     * @return true if the user can be suspended
     */
    public boolean canBeSuspended() {
        return this == ACTIVE || this == INACTIVE || this == PENDING;
    }
    
    /**
     * Checks if the user can be blocked from this status.
     * 
     * @return true if the user can be blocked
     */
    public boolean canBeBlocked() {
        return this != BLOCKED;
    }
}
