import frappe

class DBRestoreService:
    @staticmethod
    def massage_customer_address_contact_links():
        """Fixes the links between Customer, Address, and Contacts from legacy data that may have been imported without proper linking."""
        # use emojis in print statments to make it more fun and visually distinct in the logs
        print("DEBUG: 🛠️ Starting to massage customer, address, and contact links")
        all_addresses = frappe.get_all("Address", pluck="name")
        print(f"DEBUG: Found {len(all_addresses)} addresses to process")
        all_customers = frappe.get_all("Customer", pluck="name")
        print(f"DEBUG: Found {len(all_customers)} customers to process")
        all_leads = frappe.get_all("Lead", pluck="name")
        print(f"DEBUG: Found {len(all_leads)} leads to process")
        all_contacts = frappe.get_all("Contact", pluck="name")
        print(f"DEBUG: Found {len(all_contacts)} contacts to process")
        
        # query all customer doctypes that don't have an empty array for custom_select_address. This field is a child table so get_all cannot be used. We need to use a custom sql query
        # the child table is a doctype called "Custom "
        # print(f"DEBUG: Found {len(customers_with_addresses)} customers with addresses to process")