#!/usr/bin/env python3
"""Seed TLD prices by running a scrape from Porkbun API."""
import asyncio
import sys
from pathlib import Path

# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))

from app.database import AsyncSessionLocal, init_db
from app.services.tld_scraper.aggregator import tld_aggregator


async def seed_prices():
    """Run initial TLD price scrape."""
    print("Initializing database...")
    await init_db()
    
    print("Starting TLD price scrape from Porkbun API...")
    print("This may take 15-30 seconds...")
    
    async with AsyncSessionLocal() as db:
        result = await tld_aggregator.run_scrape(db)
        
        print()
        print("=" * 50)
        print("Seed Results:")
        print(f"  Status: {result.status}")
        print(f"  TLDs scraped: {result.tlds_scraped}")
        print(f"  Prices saved: {result.prices_saved}")
        print(f"  Sources: {result.sources_succeeded}/{result.sources_attempted}")
        
        if result.errors:
            print(f"  Errors: {result.errors}")
        
        print("=" * 50)
        
        if result.status == "success":
            print("\n✅ TLD prices seeded successfully!")
        else:
            print("\n⚠️ Seed completed with warnings")


if __name__ == "__main__":
    asyncio.run(seed_prices())

