from odoo import api, SUPERUSER_ID

def uninstall_hook(env):
    """
    Synchronized uninstallation: When Dine360 Shivasakthi Restaurant Suite is uninstalled,
    automatically trigger uninstallation for all its core sub-modules.
    """
    modules_to_uninstall = [
        'dine360_dashboard',
        'dine360_restaurant',
        'dine360_theme_shivasakthi',
        'dine360_kds',
        'dine360_reservation'
    ]
    
    # Search for these modules if they are installed
    modules = env['ir.module.module'].search([
        ('name', 'in', modules_to_uninstall),
        ('state', '=', 'installed')
    ])
    
    if modules:
        # Mark modules for uninstallation
        modules.button_uninstall()
