"""Seed all sample data into PostgreSQL. Run with: python seed_all.py"""
import uuid
import sys
import os
sys.path.insert(0, os.path.dirname(__file__))

from datetime import date, timedelta, datetime
from app.database import SessionLocal, engine, Base
from app.models.user import User, Role, Permission, UserRole, RolePermission
from app.models.branch import Branch
from app.models.plant import PlantCategory, PlantVariety, Plant
from app.models.supplier import Supplier
from app.models.customer import Customer
from app.models.employee import Employee
from app.models.inventory import InventoryItem, InventoryTransaction
from app.models.production import SeedLot, ProductionBatch, GerminationRecord, TransplantRecord
from app.models.purchase import PurchaseRequest, PurchaseOrder, PurchaseItem, GoodsReceiptNote
from app.models.sale import Sale, SaleItem, Quotation, QuotationItem
from app.models.finance import Account, Expense, Income, Payment, JournalEntry
from app.models.treatment import Treatment, TreatmentDetail, HealthRecord, DiseasePestRecord, TreatmentSchedule
from app.models.passport import PlantPassport, PassportTimelineEvent, PassportPhoto, PassportScanLog
from app.models.alert import Notification, Alert
from app.models.audit import AuditLog

def uid():
    return str(uuid.uuid4())

def seed():
    db = SessionLocal()
    try:
        admin = db.query(User).filter(User.username == "admin").first()
        if not admin:
            print("No admin user found. Start the server first to seed defaults.")
            return
        admin_id = admin.id

        branch = db.query(Branch).first()
        if not branch:
            branch = Branch(code="BR-001", name="Main Branch", address="Head Office", city="Dhaka", is_active=True)
            db.add(branch)
            db.flush()

        today = date.today()

        # ── Plant Categories ──
        cats = {}
        for name, icon in [
            ("Fruit Plant", "🍎"), ("Flower Plant", "🌸"), ("Vegetable Seedling", "🥬"),
            ("Indoor Plant", "🏡"), ("Outdoor Plant", "🌳"), ("Ornamental Plant", "🌺"),
            ("Herbs", "🌿"), ("Succulent", "🌵"),
        ]:
            c = PlantCategory(name=name, description=f"{name} category", icon=icon)
            db.add(c); db.flush()
            cats[name] = c

        # ── Plant Varieties ──
        vars_ = {}
        var_to_cat = {}
        var_data = [
            ("Mango", "Fruit Plant", "perennial", "Summer", "full_sun", "moderate", "loamy"),
            ("Rose", "Flower Plant", "perennial", "Spring", "full_sun", "moderate", "loamy"),
            ("Tomato", "Vegetable Seedling", "annual", "Spring", "full_sun", "high", "loamy"),
            ("Tulsi", "Herbs", "annual", "Year-round", "full_sun", "moderate", "sandy"),
            ("Aloe Vera", "Succulent", "perennial", "Year-round", "partial_shade", "low", "sandy"),
            ("Money Plant", "Indoor Plant", "perennial", "Year-round", "partial_shade", "moderate", "loamy"),
            ("Neem", "Outdoor Plant", "perennial", "Summer", "full_sun", "low", "loamy"),
            ("Jasmine", "Flower Plant", "perennial", "Spring", "full_sun", "moderate", "loamy"),
            ("Marigold", "Flower Plant", "annual", "Summer", "full_sun", "moderate", "loamy"),
            ("Mint", "Herbs", "perennial", "Year-round", "partial_shade", "high", "loamy"),
        ]
        for vname, cat_name, lc, gs, sun, water, soil in var_data:
            v = PlantVariety(name=vname, category_id=cats[cat_name].id, plant_type="Outdoor",
                             life_cycle=lc, growing_season=gs, sunlight=sun,
                             water_requirement=water, soil_type=soil)
            db.add(v); db.flush()
            vars_[vname] = v
            var_to_cat[vname] = cat_name

        # ── Plants ──
        plants = {}
        plant_data = [
            ("Mango", "Mango", "Mangifera indica", "Mango", 350, 280, 220),
            ("Rose", "Rose", "Rosa indica", "Rose", 150, 120, 90),
            ("Tomato", "Tomato", "Solanum lycopersicum", "Tomato", 60, 45, 35),
            ("Tulsi", "Tulsi", "Ocimum tenuiflorum", "Tulsi", 80, 60, 45),
            ("Aloe Vera", "Aloe Vera", "Aloe barbadensis", "Aloe Vera", 200, 160, 120),
            ("Money Plant", "Money Plant", "Epipremnum aureum", "Money Plant", 120, 90, 70),
            ("Neem", "Neem", "Azadirachta indica", "Neem", 180, 140, 100),
            ("Jasmine", "Jasmine", "Jasminum multiflorum", "Jasmine", 250, 200, 150),
            ("Marigold", "Marigold", "Tagetes erecta", "Marigold", 40, 30, 22),
            ("Mint", "Mint", "Mentha spicata", "Mint", 50, 38, 28),
        ]
        for i, (code, name, sci, vname, retail, wholesale, dealer) in enumerate(plant_data, 1):
            cat_name = var_to_cat[vname]
            p = Plant(code=f"PLT-2026-{i:06d}", name=name, scientific_name=sci,
                      variety_id=vars_[vname].id, category_id=cats[cat_name].id,
                      retail_price=retail, wholesale_price=wholesale, dealer_price=dealer, is_active=True)
            db.add(p); db.flush()
            plants[name] = p

        # ── Suppliers ──
        suppliers = {}
        for code, name, contact, phone, city in [
            ("SUP-001", "Green Seeds Co.", "Rahim Uddin", "01711001001", "Dhaka"),
            ("SUP-002", "Nursery World", "Kamal Hossain", "01711001002", "Chittagong"),
            ("SUP-003", "Bio Fertilizers Ltd", "Fatema Begum", "01711001003", "Rajshahi"),
            ("SUP-004", "Dhaka Agro Supply", "Abdur Rob", "01711001004", "Dhaka"),
        ]:
            s = Supplier(code=code, name=name, contact_person=contact, phone=phone, city=city, is_active=True)
            db.add(s); db.flush()
            suppliers[code] = s

        # ── Customers ──
        customers = {}
        for code, name, ctype, phone, city in [
            ("CUS-001", "Ravi Gardens", "Wholesale", "01811001001", "Dhaka"),
            ("CUS-002", "City Landscapers", "Corporate", "01811001002", "Dhaka"),
            ("CUS-003", "Anita Patel", "Retail", "01811001003", "Gazipur"),
            ("CUS-004", "Green View Park", "Corporate", "01811001004", "Chittagong"),
            ("CUS-005", "Sakib Rahman", "Retail", "01811001005", "Sylhet"),
        ]:
            c = Customer(code=code, name=name, customer_type=ctype, phone=phone, city=city, is_active=True)
            db.add(c); db.flush()
            customers[code] = c

        # ── Employees ──
        employees = {}
        emp_data = [
            ("EMP-001", "Rajesh Kumar", "01911001001", "Production Supervisor", "Production", 25000),
            ("EMP-002", "Priya Sharma", "01911001002", "Nursery Worker", "Production", 18000),
            ("EMP-003", "Amit Patel", "01911001003", "Sales Executive", "Sales", 22000),
            ("EMP-004", "Sunita Devi", "01911001004", "Accountant", "Finance", 28000),
            ("EMP-005", "Karim Uddin", "01911001005", "Warehouse Manager", "Inventory", 20000),
        ]
        for code, name, phone, role, dept, salary in emp_data:
            e = Employee(code=code, name=name, phone=phone, role=role, department=dept,
                         salary=salary, joining_date=today - timedelta(days=180), is_active=True)
            db.add(e); db.flush()
            employees[code] = e

        # ── Seed Lots ──
        seed_lots = {}
        for i, (pname, sup_code, qty, cost) in enumerate([
            ("Mango", "SUP-001", 5000, 0.50),
            ("Rose", "SUP-002", 10000, 0.30),
            ("Tomato", "SUP-001", 8000, 0.20),
            ("Jasmine", "SUP-003", 3000, 0.80),
            ("Aloe Vera", "SUP-004", 2000, 1.00),
            ("Marigold", "SUP-002", 12000, 0.15),
            ("Mint", "SUP-003", 4000, 0.25),
            ("Tulsi", "SUP-001", 6000, 0.35),
        ], 1):
            sl = SeedLot(lot_number=f"SL-2026-{i:03d}", plant_id=plants[pname].id,
                         supplier_id=suppliers[sup_code].id, quantity=qty, unit="seeds",
                         purchase_date=today - timedelta(days=60), cost_per_unit=cost)
            db.add(sl); db.flush()
            seed_lots[pname] = sl

        # ── Production Batches ──
        batches = {}
        batch_data = [
            ("Mango", "Mango", 30, 28, "germination", "TRAY-A1", "Greenhouse 1"),
            ("Rose", "Rose", 50, 45, "growing", "TRAY-B1", "Greenhouse 2"),
            ("Tomato", "Tomato", 60, 55, "ready", "TRAY-C1", "Field A"),
            ("Jasmine", "Jasmine", 25, 22, "growing", "TRAY-D1", "Greenhouse 1"),
            ("Aloe Vera", "Aloe Vera", 40, 38, "germination", "TRAY-E1", "Greenhouse 3"),
            ("Marigold", "Marigold", 70, 65, "ready", "TRAY-F1", "Field B"),
            ("Mint", "Mint", 45, 42, "sowing", "TRAY-G1", "Greenhouse 2"),
            ("Tulsi", "Tulsi", 35, 30, "growing", "TRAY-H1", "Greenhouse 1"),
        ]
        for i, (pname, plant_name, sq, cq, status, tray, loc) in enumerate(batch_data, 1):
            b = ProductionBatch(
                batch_number=f"BAT-2026-{i:06d}", plant_id=plants[plant_name].id,
                seed_lot_id=seed_lots[pname].id,
                sowing_date=today - timedelta(days=45),
                expected_ready_date=today + timedelta(days=30),
                sown_quantity=sq, current_quantity=cq, status=status,
                tray_number=tray, location=loc, employee_id=employees["EMP-001"].id,
                branch_id=branch.id,
            )
            db.add(b); db.flush()
            batches[pname] = b

        # ── Germination Records ──
        for pname in ["Mango", "Rose", "Tomato", "Jasmine", "Aloe Vera"]:
            g = GerminationRecord(batch_id=batches[pname].id,
                                  date=today - timedelta(days=35),
                                  germinated_quantity=batches[pname].current_quantity,
                                  success_rate=batches[pname].current_quantity / max(batches[pname].sown_quantity, 1) * 100)
            db.add(g)

        # ── Transplant Records ──
        for pname in ["Rose", "Tomato"]:
            t = TransplantRecord(batch_id=batches[pname].id, date=today - timedelta(days=20),
                                 from_container="Seedling Tray", to_container="Polybag 6x8",
                                 quantity=batches[pname].current_quantity, employee_id=employees["EMP-002"].id)
            db.add(t)

        # ── Inventory Items ──
        inv_items = {}
        inv_data = [
            ("INV-001", "Polybag 6x8", "consumable", "Packaging", "piece", 5000, 200, 5, 8),
            ("INV-002", "Cocopeat Block", "consumable", "Growing Medium", "kg", 200, 45, 30, 55),
            ("INV-003", "NPK Fertilizer 16-16-16", "consumable", "Fertilizer", "kg", 150, 120, 80, 140),
            ("INV-004", "Neem Oil 1L", "consumable", "Pesticide", "piece", 50, 180, 120, 220),
            ("INV-005", "Garden Sprayer 5L", "equipment", "Tools", "piece", 20, 850, 600, 1000),
            ("INV-006", "Wheelbarrow", "equipment", "Tools", "piece", 8, 3500, 2500, 4000),
            ("INV-007", "Drip Irrigation Kit", "equipment", "Irrigation", "set", 15, 5000, 3500, 6500),
            ("INV-008", "Seedling Trays 50-cell", "consumable", "Packaging", "piece", 100, 120, 80, 150),
            ("INV-009", "Garden Gloves", "equipment", "Safety", "pair", 30, 250, 150, 300),
            ("INV-010", "Pruning Shears", "equipment", "Tools", "piece", 12, 650, 450, 800),
        ]
        for code, name, cat, sub, unit, qty, sell, cost, _ in inv_data:
            it = InventoryItem(code=code, name=name, category=cat, subcategory=sub,
                               unit=unit, quantity=qty, min_quantity=20,
                               cost_price=cost, sell_price=sell, location="Warehouse A",
                               status="in_stock", branch_id=branch.id)
            db.add(it); db.flush()
            inv_items[code] = it

        # ── Inventory Transactions ──
        for code in ["INV-001", "INV-002", "INV-003"]:
            it = InventoryTransaction(item_id=inv_items[code].id, type="purchase",
                                      quantity=inv_items[code].quantity, notes="Initial stock",
                                      created_by=admin_id)
            db.add(it)

        # ── Purchase Orders ──
        pos = {}
        po_data = [
            ("PO-2026-001", "SUP-001", 15000, "received"),
            ("PO-2026-002", "SUP-002", 8000, "confirmed"),
            ("PO-2026-003", "SUP-003", 12000, "draft"),
        ]
        for code, sup, total, status in po_data:
            po = PurchaseOrder(po_number=code, supplier_id=suppliers[sup].id,
                               order_date=today - timedelta(days=30),
                               expected_date=today + timedelta(days=10),
                               total=total, status=status, created_by=admin_id)
            db.add(po); db.flush()
            pos[code] = po

        # ── Purchase Items ──
        for po_code, inv_code, desc, qty, price in [
            ("PO-2026-001", "INV-001", "Polybag 6x8 - Bulk", 2000, 5),
            ("PO-2026-001", "INV-003", "NPK Fertilizer", 50, 80),
            ("PO-2026-002", "INV-002", "Cocopeat Block", 100, 30),
            ("PO-2026-003", "INV-007", "Drip Irrigation Kit", 5, 3500),
        ]:
            pi = PurchaseItem(order_id=pos[po_code].id, inventory_id=inv_items[inv_code].id,
                              description=desc, quantity=qty, unit_price=price, total=qty*price)
            db.add(pi)

        # ── GRN ──
        grn = GoodsReceiptNote(grn_number="GRN-2026-001", purchase_order_id=pos["PO-2026-001"].id,
                               supplier_id=suppliers["SUP-001"].id, received_date=today - timedelta(days=25),
                               total=15000, status="received", received_by=admin_id)
        db.add(grn)

        # ── Sales ──
        sales = {}
        sale_data = [
            ("INV-2026-001", "CUS-001", "retail", 3500, 200, 0, 3700, 3700, 0, "paid"),
            ("INV-2026-002", "CUS-002", "wholesale", 8200, 500, 0, 8700, 5000, 3700, "partial"),
            ("INV-2026-003", "CUS-003", "retail", 1200, 0, 0, 1200, 1200, 0, "paid"),
            ("INV-2026-004", "CUS-004", "wholesale", 15000, 1000, 0, 16000, 10000, 6000, "partial"),
            ("INV-2026-005", "CUS-005", "retail", 2400, 100, 0, 2500, 2500, 0, "paid"),
        ]
        for inv_num, cust, stype, sub, disc, tax, total, paid, due, status in sale_data:
            s = Sale(invoice_number=inv_num, customer_id=customers[cust].id, sale_type=stype,
                     date=today - timedelta(days=15), subtotal=sub, discount=disc, tax=tax,
                     total=total, paid=paid, due=due, status=status, payment_method="cash",
                     created_by=admin_id)
            db.add(s); db.flush()
            sales[inv_num] = s

        # ── Sale Items ──
        plant_names = ["Mango", "Rose", "Tomato", "Aloe Vera", "Jasmine"]
        for i, (inv_num, pname, qty, price) in enumerate([
            ("INV-2026-001", "Mango", 5, 350), ("INV-2026-001", "Rose", 10, 150),
            ("INV-2026-002", "Rose", 30, 150), ("INV-2026-002", "Tomato", 40, 60),
            ("INV-2026-003", "Aloe Vera", 4, 200), ("INV-2026-003", "Mint", 10, 50),
            ("INV-2026-004", "Mango", 20, 350), ("INV-2026-004", "Jasmine", 20, 250),
            ("INV-2026-005", "Marigold", 20, 40), ("INV-2026-005", "Tulsi", 10, 80),
        ]):
            si = SaleItem(sale_id=sales[inv_num].id, plant_id=plants[pname].id,
                          description=pname, quantity=qty, unit_price=price, total=qty*price)
            db.add(si)

        # ── Quotations ──
        q1 = Quotation(quote_number="QT-2026-001", customer_id=customers["CUS-002"].id,
                       date=today - timedelta(days=10), valid_until=today + timedelta(days=20),
                       subtotal=25000, total=25000, status="accepted", created_by=admin_id)
        db.add(q1); db.flush()
        for pname, qty, price in [("Mango", 50, 280), ("Rose", 100, 120)]:
            qi = QuotationItem(quotation_id=q1.id, plant_id=plants[pname].id,
                               description=pname, quantity=qty, unit_price=price, total=qty*price)
            db.add(qi)

        # ── Finance Accounts ──
        accounts = {}
        for name, atype, bal in [
            ("Main Cash", "cash", 50000),
            ("Bank Account", "bank", 250000),
            ("Petty Cash", "cash", 10000),
        ]:
            a = Account(name=name, type=atype, balance=bal, is_active=True)
            db.add(a); db.flush()
            accounts[name] = a

        # ── Expenses ──
        for i, (cat, desc, amt, days_ago) in enumerate([
            ("Utilities", "Electricity Bill - June", 8500, 15),
            ("Utilities", "Water Bill - June", 3200, 15),
            ("Salary", "Employee Salaries - June", 113000, 10),
            ("Maintenance", "Greenhouse Repair", 5000, 8),
            ("Transport", "Delivery Fuel", 2500, 5),
            ("Supplies", "Office Supplies", 1500, 3),
        ], 1):
            e = Expense(expense_number=f"EXP-2026-{i:03d}", category=cat, description=desc,
                        amount=amt, date=today - timedelta(days=days_ago),
                        payment_method="bank", account_id=accounts["Bank Account"].id,
                        created_by=admin_id)
            db.add(e)

        # ── Income ──
        for i, (cat, desc, amt, days_ago) in enumerate([
            ("Sales", "Plant Sales Revenue", 25000, 10),
            ("Sales", "Wholesale Order Payment", 15000, 5),
            ("Services", "Landscaping Service", 8000, 3),
        ], 1):
            inc = Income(income_number=f"INC-2026-{i:03d}", category=cat, description=desc,
                         amount=amt, date=today - timedelta(days=days_ago),
                         payment_method="bank", account_id=accounts["Bank Account"].id,
                         created_by=admin_id)
            db.add(inc)

        # ── Treatments ──
        treatments = {}
        for i, (pname, ttype, cost, days_ago, emp) in enumerate([
            ("Mango", "fertilizer", 2000, 20, "EMP-001"),
            ("Rose", "pesticide", 1500, 15, "EMP-002"),
            ("Tomato", "irrigation", 500, 10, "EMP-002"),
            ("Jasmine", "fertilizer", 1800, 8, "EMP-001"),
            ("Aloe Vera", "inspection", 300, 5, "EMP-001"),
        ], 1):
            t = Treatment(treatment_number=f"TRT-2026-{i:03d}", batch_id=batches[pname].id,
                          variety_id=vars_[pname].id, treatment_type=ttype,
                          treatment_date=today - timedelta(days=days_ago),
                          employee_id=employees[emp].id, status="completed",
                          cost=cost, created_by=admin_id)
            db.add(t); db.flush()
            treatments[pname] = t

        # ── Treatment Details ──
        td = TreatmentDetail(treatment_id=treatments["Mango"].id,
                             fertilizer_name="NPK 16-16-16", npk_ratio="16-16-16",
                             dose="50g", unit="g", application_method="soil drench")
        db.add(td)
        td2 = TreatmentDetail(treatment_id=treatments["Rose"].id,
                              product_name="Neem Oil", active_ingredient="Azadirachtin",
                              target_pest_disease="Aphids", dosage="5ml/L", spray_method="foliar spray")
        db.add(td2)
        td3 = TreatmentDetail(treatment_id=treatments["Tomato"].id,
                              watering_method="drip", duration_minutes=30, quantity_liters=50)
        db.add(td3)

        # ── Health Records ──
        for pname, height, leaves, score in [
            ("Mango", 25, 8, 85), ("Rose", 30, 12, 90), ("Tomato", 40, 15, 78),
            ("Jasmine", 20, 6, 82), ("Aloe Vera", 15, 10, 95),
        ]:
            hr = HealthRecord(batch_id=batches[pname].id, record_date=today - timedelta(days=3),
                              plant_height_cm=height, leaf_count=leaves, health_score=score,
                              plant_color="green", root_status="healthy", mortality_rate=0,
                              recorded_by=admin_id)
            db.add(hr)

        # ── Disease/Pest Records ──
        dp = DiseasePestRecord(batch_id=batches["Rose"].id, record_date=today - timedelta(days=12),
                               name="Aphid Infestation", type="pest", severity="medium",
                               symptoms="Small green insects on leaves", treatment_applied="Neem oil spray",
                               product_used="Neem Oil 1L", status="resolved", recorded_by=admin_id)
        db.add(dp)

        # ── Treatment Schedules ──
        for pname, ttype, freq, emp in [
            ("Mango", "irrigation", 3, "EMP-002"),
            ("Rose", "fertilizer", 14, "EMP-001"),
            ("Tomato", "pesticide", 7, "EMP-002"),
        ]:
            ts = TreatmentSchedule(batch_id=batches[pname].id, treatment_type=ttype,
                                   frequency_days=freq, next_due_date=today + timedelta(days=freq),
                                   employee_id=employees[emp].id, is_active=True, created_by=admin_id)
            db.add(ts)

        # ── Plant Passports ──
        passports = {}
        for i, (pname, plant_name) in enumerate([
            ("Mango", "Mango"), ("Rose", "Rose"), ("Tomato", "Tomato"),
            ("Jasmine", "Jasmine"), ("Aloe Vera", "Aloe Vera"),
        ], 1):
            cat_name = var_to_cat[pname]
            pp = PlantPassport(
                passport_id=f"CHR-PLT-2026-{i:06d}",
                batch_id=batches[pname].id, plant_id=plants[plant_name].id,
                variety_id=vars_[pname].id, category_id=cats[cat_name].id,
                branch_id=branch.id,
                plant_name=plant_name, scientific_name=plants[plant_name].scientific_name,
                variety_name=pname, category_name=vars_[pname].name,
                batch_number=batches[pname].batch_number,
                seed_lot_number=seed_lots[pname].lot_number,
                sowing_date=batches[pname].sowing_date,
                current_growth_stage=batches[pname].status,
                expected_ready_date=batches[pname].expected_ready_date,
                current_stock=batches[pname].current_quantity,
                nursery_zone="Zone A", greenhouse="Greenhouse 1",
                selling_price=plants[plant_name].retail_price,
                wholesale_price=plants[plant_name].wholesale_price,
                health_status="healthy", health_score=88.0,
                leaf_color="dark green", plant_height_cm=25.0,
                root_condition="healthy", mortality_risk="low",
            )
            db.add(pp); db.flush()
            passports[pname] = pp

        # ── Passport Timeline Events ──
        for pname in ["Mango", "Rose", "Tomato"]:
            for j, (etype, title, days_ago) in enumerate([
                ("sowing", "Seeds sown", 45),
                ("germination", "Germination observed", 30),
                ("transplant", "Transplanted to polybags", 20),
                ("health_check", "Routine health check", 5),
            ]):
                pte = PassportTimelineEvent(passport_id=passports[pname].id,
                                            event_date=today - timedelta(days=days_ago),
                                            event_type=etype, event_title=title,
                                            icon=etype, recorded_by=admin_id)
                db.add(pte)

        # ── Passport Scan Logs ──
        for pname in ["Mango", "Rose"]:
            ps = PassportScanLog(passport_id=passports[pname].id, scanned_by="Customer",
                                 scan_source="qr_code", device_info="iPhone 15",
                                 ip_address="192.168.1.100")
            db.add(ps)

        # ── Alerts ──
        a1 = Alert(alert_type="low_stock", title="Low Stock Alert",
                   message="Polybag 6x8 running low (500 remaining)", severity="medium")
        db.add(a1)
        a2 = Alert(alert_type="batch_ready", title="Batch Ready",
                   message="BAT-2026-000003 (Tomato) is ready for sale", severity="low")
        db.add(a2)

        # ── Notifications ──
        n1 = Notification(user_id=admin_id, title="Welcome", message="Welcome to NurseryOps!",
                          type="info")
        db.add(n1)

        db.commit()
        print("✓ All sample data seeded successfully!")
        print(f"  Categories: 8 | Varieties: 10 | Plants: 10")
        print(f"  Suppliers: 4 | Customers: 5 | Employees: 5")
        print(f"  Seed Lots: 8 | Batches: 8")
        print(f"  Inventory: 10 | Purchase Orders: 3")
        print(f"  Sales: 5 | Quotations: 1 | Accounts: 3")
        print(f"  Expenses: 6 | Income: 3")
        print(f"  Treatments: 5 | Health Records: 5 | Passports: 5")
    except Exception as e:
        db.rollback()
        print(f"Error: {e}")
        import traceback; traceback.print_exc()
    finally:
        db.close()

if __name__ == "__main__":
    seed()
