# -*- coding: utf-8 -*-
from pathlib import Path
import re
import sys

server = Path(sys.argv[1]).resolve()
relay_path = server / 'relay_server_clean.py'
if not relay_path.is_file():
    raise SystemExit('relay_server_clean.py not found')
text = relay_path.read_text(encoding='utf-8')
text = re.sub(r'^VERSION\s*=\s*["\'][^"\']+["\']', 'VERSION  = "2.4.9.398-direct-preview-universal-security-anonymity"', text, count=1, flags=re.M)
marker = '# BEGIN V249398_DIRECT_PREVIEW_UNIVERSAL_SECURITY_ANONYMITY_DIAGNOSTIC'
if marker not in text:
    text += r'''

# BEGIN V249398_DIRECT_PREVIEW_UNIVERSAL_SECURITY_ANONYMITY_DIAGNOSTIC
@app.get("/api/diagnostics/publish_security_scope_v249398")
def api_diagnostics_publish_security_scope_v249398():
    return {
        "ok": True,
        "version": "V249398-direct-preview-universal-security-anonymity",
        "publication_default_route": "direct_preview",
        "professional_workspace_file_selection_opens_preview": True,
        "generic_plus_media_opens_preview": True,
        "dm_security_menu": "full_e2ee_standard_aes_or_plaintext",
        "group_room_community_security_menu": "shared_aes_gcm_or_plaintext",
        "group_full_e2ee_claimed_active": False,
        "conversation_identity_modes": ["profile", "anonymous_display"],
        "anonymous_display_hides_ip": False,
        "database_deleted": False,
        "media_deleted": False,
    }
# END V249398_DIRECT_PREVIEW_UNIVERSAL_SECURITY_ANONYMITY_DIAGNOSTIC
'''
relay_path.write_text(text, encoding='utf-8')
print('PATCH_SERVER_V249398=OK')
