from repositories.tenant_repository import tenant_repository DEFAULT_CHECKLIST = { 'add_competitor': False, 'run_analysis': False, 'template_imported': False, 'sidebar_installed': False, 'sync_from_sheet': False, 'tour_completed': False, 'tour_skipped': False, 'tour_step': 0, } def update_onboarding(tenant_id, updates): """ Merges partial onboarding_checklist updates into a tenant's record. Used both by the guided-tour composable (tour_step, tour_completed, tour_skipped) and by checklist auto-completion logic elsewhere (add_competitor, run_analysis, template_imported — set from AccountPage's verification helper, sidebar_installed — set on first successful validateLicence(), sync_from_sheet — set on first successful pullLatestResults()). Data flow: tenant_id + partial onboarding dict → existing onboarding_checklist read → merged with updates (existing keys not in `updates` are preserved) → PocketBase tenants record updated → merged checklist returned """ tenant = tenant_repository.get_by_id(tenant_id) if not tenant: raise ValueError(f'Unknown tenant: {tenant_id}') current = tenant.get('onboarding_checklist') or DEFAULT_CHECKLIST merged = {**current, **updates} tenant_repository.update(tenant_id, {'onboarding_checklist': merged}) return merged