import json

# Load machines
with open('machines.json', 'r', encoding='utf-8') as f:
    machines = json.load(f)

# Update all machines with backup
updated_count = 0
already_backed_up = 0

print("Updating machines with OneDrive backup...\n")

for machine in machines:
    if machine.get('backup_status') == 'No':
        machine['backup_status'] = 'Yes'
        # Add backup type field
        machine['backup_type'] = 'OneDrive'
        updated_count += 1
        print(f"✓ UPDATED: {machine['machine_code']} - {machine.get('computer_name', 'Unknown')} - Assigned to: {machine.get('assigned_to', 'N/A')}")
    else:
        already_backed_up += 1
        # Ensure backup_type is set
        if 'backup_type' not in machine or not machine.get('backup_type'):
            machine['backup_type'] = 'OneDrive'

# Save back
with open('machines.json', 'w', encoding='utf-8') as f:
    json.dump(machines, f, indent=4, ensure_ascii=False)

print(f"\n✅ Done!")
print(f"   Updated to have backup: {updated_count} machines")
print(f"   Already had backup: {already_backed_up} machines")
print(f"   Total machines: {len(machines)}")
print(f"\n📊 All machines now have backup protection!")
print(f"   Backup Type: OneDrive (Any cloud backup counts: OneDrive, Google Drive, etc.)")
