"""Seed sample cost + harvest records for ROI demo."""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from datetime import date, timedelta
from app.database import SessionLocal
from app.models.plant_activation import PlantActivation, PlantCostRecord
from app.models.plant_lifecycle import PlantHarvestRecord
import uuid

db = SessionLocal()
activations = db.query(PlantActivation.id).all()
act_ids = [a[0] for a in activations]

cost_data = [
    ("Fertilizer", 1200, "NPK 20-20-20 fertilizer"),
    ("Pesticide", 800, "Neem oil + imidacloprid"),
    ("Labor", 2000, "Planting and daily care labor"),
    ("Seeds", 500, "Premium hybrid seeds"),
    ("Irrigation", 600, "Drip irrigation setup"),
    ("Transport", 300, "Market transport"),
    ("Equipment", 400, "Sprayer rental"),
]

harvest_data = [
    (12.5, "kg", "A", 4500, "Local market"),
    (8.0, "kg", "B", 2400, "Wholesale buyer"),
    (5.5, "kg", "A", 2200, "Direct sale"),
]

harvest_num = 0
for act_id in act_ids:
    for i, (cost_type, amount, desc) in enumerate(cost_data):
        db.add(PlantCostRecord(
            id=str(uuid.uuid4()),
            activation_id=act_id,
            cost_type=cost_type,
            amount=amount,
            description=desc,
            date=date.today() - timedelta(days=30 - i * 4),
            notes=f"Sample {cost_type.lower()} cost",
        ))

    for qty, unit, grade, revenue, buyer in harvest_data:
        harvest_num += 1
        db.add(PlantHarvestRecord(
            id=str(uuid.uuid4()),
            harvest_number=f"HRV-{harvest_num:04d}",
            activation_id=act_id,
            harvest_date=date.today() - timedelta(days=harvest_num),
            quantity=qty,
            unit=unit,
            grade=grade,
            revenue=revenue,
            buyer=buyer,
            notes=f"Grade {grade} harvest",
        ))

db.commit()
print(f"Seeded {len(cost_data) * len(act_ids)} cost records + {len(harvest_data) * len(act_ids)} harvest records for {len(act_ids)} activations.")
db.close()
