#!/usr/bin/env python
"""
Script to update all notification functions to use the get_site_url function.
"""
import os
import re

# Path to the notifications utils file
utils_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 
                         'notifications', 'utils.py')

# Read the file content
with open(utils_file, 'r') as f:
    content = f.read()

# Pattern to match the site URL retrieval code in each function
pattern = r"""    # Get the site domain for links
    from django.contrib.sites.models import Site
    try:
        domain = Site.objects.get_current\(\).domain
        site_url = f"https://{domain}"
    except:
        site_url = "https://smarthr.ictaz.org.zm"  # Fallback to production URL"""

# Replacement code
replacement = """    # Get the site URL for links
    site_url = get_site_url(request)"""

# Replace all occurrences
updated_content = re.sub(pattern, replacement, content)

# Write the updated content back to the file
with open(utils_file, 'w') as f:
    f.write(updated_content)

print(f"Updated {utils_file}")
