-- Erase legacy QBO sync data so it doesn't conflict with the active Zoho integration

-- Clear QBO references on company bank transactions
UPDATE public.company_bank_transactions
SET qbo_id = NULL,
    qbo_sync_status = NULL
WHERE qbo_id IS NOT NULL OR qbo_sync_status IS NOT NULL;

-- Clear QBO references on client invoices (no rows currently, but reset for safety)
UPDATE public.client_invoices
SET qbo_invoice_id = NULL,
    qbo_sync_status = 'not_synced',
    qbo_synced_at = NULL,
    qbo_sync_error = NULL
WHERE qbo_invoice_id IS NOT NULL
   OR qbo_sync_status NOT IN ('not_synced')
   OR qbo_synced_at IS NOT NULL
   OR qbo_sync_error IS NOT NULL;

-- Wipe the QBO sync log entirely
TRUNCATE TABLE public.qbo_sync_log;