#!/usr/bin/env python3
"""Apply Batch 2 updates"""
import csv
import json
import shutil
from datetime import datetime

# Backup
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
shutil.copy('verified-scored-facilities.csv', f'verified-scored-facilities-BACKUP-{timestamp}.csv')

# Read CSV
with open('verified-scored-facilities.csv', 'r', encoding='utf-8') as f:
    reader = csv.DictReader(f)
    rows = list(reader)
    fieldnames = reader.fieldnames

# Batch 2 updates
updates = {
    "Traverse Cold Storage": {
        "Total Rooms": "15+",
        "Square Footage": "116,000",
        "Primary Produce": "Apple Cherry",
        "Premium Varieties": "Frozen products, apples, cherries",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "90",
        "Verification Source": "MapQuest, Refrigerated & Frozen Foods, Traverse Connect",
        "Confidence Level": "Verified",
        "Notes": "2695 Cass Rd, Traverse City MI. 116K sq ft sub-zero facility. 270,000 cubic ft freezer space. Largest public refrigerated warehouse in Northern Michigan. IARW/GCCA member. Part of Grand Traverse Trucking."
    },
    "Henningsen Cold Storage - Portland": {
        "Total Rooms": "30+",
        "Square Footage": "280,000",
        "Primary Produce": "Multi-temp Storage",
        "Premium Varieties": "Multi-temperature products (-20°F to +40°F)",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "95",
        "Verification Source": "FleetOwner, Henningsen.com, Frozen Foods Biz",
        "Confidence Level": "Verified",
        "Notes": "Portland OR (17400 NE Sacramento St). 7.9M cubic ft total capacity. 30,000+ pallet positions. Founded 1923. Acquired by Lineage Logistics. Convertible multi-temp rooms. High-volume throughput design."
    },
    "L&M Companies": {
        "Total Rooms": "20+",
        "Square Footage": "120,000",
        "Primary Produce": "Apples",
        "Premium Varieties": "Washington apples, pears, multiple brands",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "90",
        "Verification Source": "LMCompanies.com, MapQuest",
        "Confidence Level": "Verified",
        "Notes": "Union Gap WA: 4310 Main Street. Multi-state operations: WA, MI (1891 Territorial Rd, Benton Harbor), NC, FL, GA, CO, AZ, TX. Washington Family Farms brand. Apple King brand. Full-service logistics with LMTS division."
    }
}

# Apply updates
update_count = 0
for row in rows:
    company = row['Company']
    if company in updates:
        for key, value in updates[company].items():
            row[key] = value
        update_count += 1
        print(f"✓ Updated: {company}")

# Write updated CSV
with open('verified-scored-facilities.csv', 'w', encoding='utf-8', newline='') as f:
    writer = csv.DictWriter(f, fieldnames=fieldnames)
    writer.writeheader()
    writer.writerows(rows)

print(f"\n✅ Applied {update_count} updates")
print(f"📊 Progress: {56 + update_count}/1,390 verified ({((56 + update_count)/1390*100):.1f}%)")
