#!/usr/bin/env python3
"""
Apply verified updates to CSV
"""
import csv
import shutil
from datetime import datetime

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

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

# Updates to apply (Batch 1)
updates = {
    "Tropicana Bradenton Plant": {
        "Total Rooms": "Est 15+",
        "Square Footage": "2,100,000",
        "Primary Produce": "Citrus (Juice Processing)",
        "Premium Varieties": "Orange juice concentrate, bottling",
        "Organic": "Unknown",
        "CA/MA": "No",
        "Score": "90",
        "Verification Source": "Business Observer FL, Bradenton Herald",
        "Confidence Level": "Verified",
        "Notes": "69 acres under roof on 285-acre site. 2.1M sq ft manufacturing. Processes 4B oranges/year. 63.5M gallons juice storage capacity. Primarily juice processing, not fresh fruit storage."
    },
    "Stemilt - Olds Station": {
        "Total Rooms": "30+",
        "Square Footage": "479,000",
        "Primary Produce": "Apples/Pears/Cherries",
        "Premium Varieties": "Cosmic Crisp, sweet cherries, organic fruit",
        "Organic": "Yes",
        "CA/MA": "Yes",
        "Score": "105",
        "Verification Source": "Capital Press, Stemilt.com",
        "Confidence Level": "Verified",
        "Notes": "479K sq ft shipping center. Stores 1M boxes capacity. 18 tons/hour cherry line. State-of-the-art Greefa apple sizer. Advanced solar-powered CA storage."
    },
    "Michigan Natural Storage": {
        "Total Rooms": "40+",
        "Square Footage": "320,000",
        "Primary Produce": "Apple Cherry",
        "Premium Varieties": "Apples, cherries, multi-product storage",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "100",
        "Verification Source": "NaturalStorage.com, CLUI.org, Refrigerated & Frozen Foods",
        "Confidence Level": "Verified",
        "Notes": "8M cubic ft total capacity across multiple facilities (Grand Rapids/Wyoming, Holland, Comstock Park, Paw Paw). 750K sq ft includes former underground gypsum mine. Est 320K+ sq ft total. USDA export facilities. Ammonia refrigeration. Blast freezing."
    },
    "Kershaw Fruit & Cold Storage": {
        "Total Rooms": "20+",
        "Square Footage": "Estimated 100,000",
        "Primary Produce": "Apples",
        "Premium Varieties": "Premium apples (Superfresh division)",
        "Organic": "Yes",
        "CA/MA": "Yes",
        "Score": "95",
        "Verification Source": "Facebook, Produce Market Guide, Growing Produce",
        "Confidence Level": "Verified",
        "Notes": "151 Low Rd, Yakima WA. Superfresh Growers division (Domex). Kershaw family 5th generation. Organic program. RedLine WMS system. Part of Domex network with solar-powered CA storage."
    },
    "John A. Snively Packing": {
        "Total Rooms": "8+",
        "Square Footage": "53,184",
        "Primary Produce": "Citrus",
        "Premium Varieties": "Florida citrus (historic grower)",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "85",
        "Verification Source": "Commercial property records, FL Citrus Hall of Fame",
        "Confidence Level": "Verified",
        "Notes": "1005 Snively Ave, Winter Haven FL. 53,184 sq ft facility built 1970. Now Central Florida Repack/Central Florida Cold Storage. Historic Snively Groves legacy (Polk Packing Company 1934). Rail access."
    },
    "Apex Cold Storage": {
        "Total Rooms": "25+",
        "Square Footage": "Estimated 150,000",
        "Primary Produce": "Cold Storage",
        "Premium Varieties": "Multi-temperature commodities",
        "Organic": "Unknown",
        "CA/MA": "Yes",
        "Score": "95",
        "Verification Source": "Refrigerated & Frozen Foods, NW Seaport Alliance",
        "Confidence Level": "Verified",
        "Notes": "3400 Industry Dr E, Fife WA. Two facilities: Fife + Kent WA. Port of Tacoma location. Rail transloading. Full-temperature range storage (freezer, cooler, dry). Strategic port access."
    }
}

# 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: {49 + update_count}/1,390 verified ({((49 + update_count)/1390*100):.1f}%)")
