' Feature flags via #DEFINE — compile different code paths
#COMPILE EXE
#DIM ALL

%FEATURE_LOGGING = 1
%FEATURE_CACHE = 1
%FEATURE_DEBUG = 0
%FEATURE_SSL = 0
%FEATURE_COMPRESS = 1

FUNCTION PBMAIN() AS LONG
    LOCAL i AS LONG
    LOCAL features(10) AS LONG
    LOCAL featureName(10) AS STRING
    LOCAL featureEnabled(10) AS LONG
    LOCAL enabledCount AS LONG
    LOCAL disabledCount AS LONG
    LOCAL cacheHits AS LONG
    LOCAL cacheMisses AS LONG
    LOCAL compressLevel AS LONG
    LOCAL logLevel AS LONG
    LOCAL s AS STRING

    PRINT "=== Feature Flags ==="
    PRINT

    features(0) = 1
    featureName(0) = "LOGGING             "
    featureEnabled(0) = 1

    features(1) = 2
    featureName(1) = "CACHE               "
    featureEnabled(1) = 1

    features(2) = 3
    featureName(2) = "DEBUG               "
    featureEnabled(2) = 0

    features(3) = 4
    featureName(3) = "SSL                 "
    featureEnabled(3) = 0

    features(4) = 5
    featureName(4) = "COMPRESS            "
    featureEnabled(4) = 1

    PRINT "Feature flag configuration:"
    enabledCount = 0
    disabledCount = 0
    FOR i = 0 TO 4
        s = TRIM$(featureName(i))
        IF featureEnabled(i) = 1 THEN
            PRINT "  [+] " & s & " [ENABLED]"
            enabledCount = enabledCount + 1
        ELSE
            PRINT "  [-] " & s & " [DISABLED]"
            disabledCount = disabledCount + 1
        END IF
    NEXT i
    PRINT "  " & STR$(enabledCount) & " enabled, " & STR$(disabledCount) & " disabled"
    PRINT

    IF %FEATURE_LOGGING = 1 THEN
        PRINT "--- Logging subsystem active ---"
        logLevel = 2
        PRINT "  Log level: " & STR$(logLevel) & " (0=none, 1=error, 2=warn, 3=info)"
    END IF

    IF %FEATURE_CACHE = 1 THEN
        PRINT "--- Cache subsystem active ---"
        cacheHits = 85
        cacheMisses = 15
        PRINT "  Cache hits: " & STR$(cacheHits)
        PRINT "  Cache misses: " & STR$(cacheMisses)
        PRINT "  Hit rate: " & FORMAT$(cacheHits * 100 / (cacheHits + cacheMisses)) & "%"
    END IF

    IF %FEATURE_DEBUG = 1 THEN
        PRINT "--- Debug mode ON ---"
        PRINT "  Verbose logging, stack traces, memory checks"
    ELSE
        PRINT "--- Debug mode OFF ---"
        PRINT "  Release build optimizations"
    END IF

    IF %FEATURE_SSL = 1 THEN
        PRINT "--- SSL/TLS enabled ---"
        PRINT "  Using TLS 1.3 protocol"
    ELSE
        PRINT "--- SSL/TLS disabled ---"
        PRINT "  Plaintext connections only"
    END IF

    IF %FEATURE_COMPRESS = 1 THEN
        PRINT "--- Compression enabled ---"
        compressLevel = 6
        PRINT "  Compression level: " & STR$(compressLevel) & " (1-9)"
        PRINT "  Algorithm: Deflate"
    END IF

    PRINT
    PRINT "--- Feature toggle simulation ---"
    PRINT "If %FEATURE_CACHE were 0:"
    PRINT "  All reads go to disk directly"
    PRINT "  Slower but uses less memory"

    PRINT
    PRINT "Feature flags demonstration complete."

    FUNCTION = 0
END FUNCTION
