import sys
sys.path.append('/app')

from app.db.database import engine, Base
from app.models.models import License, Activation, Version, ApiKey
from sqlalchemy.orm import Session
import uuid
from datetime import datetime, timedelta

print("Creating database tables...")
Base.metadata.create_all(bind=engine)

with Session(engine) as db:
    # Create a test API key
    api_key = ApiKey(
        key="test-api-key-12345",
        name="Test API Key",
        is_active=True
    )
    db.add(api_key)
    
    # Create a test license
    test_license = License(
        license_key="TEST-LICENSE-KEY-12345",
        product_id="software-v1",
        customer_email="test@example.com",
        customer_name="Test Customer",
        max_activations=5,
        expires_at=datetime.utcnow() + timedelta(days=365)
    )
    db.add(test_license)
    
    # Create initial version
    initial_version = Version(
        version_number="1.0.0",
        release_notes="Initial release",
        is_mandatory=False
    )
    db.add(initial_version)
    
    db.commit()
    print("Database initialized successfully!")
    print(f"Test API Key: test-api-key-12345")
    print(f"Test License Key: TEST-LICENSE-KEY-12345")