# Script to remove the misplaced beach_design route

file_path = r'd:\bookbeach\backend\app\routes\admin_routes.py'

# Read the file
with open(file_path, 'r', encoding='utf-8') as f:
    lines = f.readlines()

# Find and remove the misplaced route
fixed_lines = []
i = 0
in_misplaced_route = False

while i < len(lines):
    line = lines[i]
    
    # Check if we're at the start of the misplaced route
    if line.strip() == '@admin_bp.route(\'/beaches/<beach_id>/design\', methods=[\'GET\'])':
        print(f"Found misplaced route at line {i+1}")
        in_misplaced_route = True
        # Skip this line and all lines until we reach the finally block of edit_market function
        while i < len(lines) and not (lines[i].strip() == 'finally:'):
            i += 1
        # Skip the finally block as well
        if i < len(lines) and lines[i].strip() == 'finally:':
            while i < len(lines) and lines[i].strip() != '':
                i += 1
        # Skip any trailing empty lines
        while i < len(lines) and lines[i].strip() == '':
            i += 1
        in_misplaced_route = False
        continue
    
    if not in_misplaced_route:
        fixed_lines.append(line)
    
    i += 1

# Write the fixed content back
with open(file_path, 'w', encoding='utf-8') as f:
    f.writelines(fixed_lines)

print("Removed misplaced beach_design route from admin_routes.py")