#!/usr/bin/env python3

import sys
import os

# Add the repo root to the Python path so we can import our modules
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import database
import config

def main():
    print("Initializing database...")
    
    # Initialize the database (creates tables and admin user)
    database.init_database()
    
    print("Seeding database with sample data...")
    
    # Add sample users
    try:
        database.add_user("john_doe", "warehouse2023", "john.doe@company.com", "manager")
        print("Added manager user: john_doe")
    except:
        print("Manager user john_doe already exists")
    
    try:
        database.add_user("mary_smith", "inventory456", "mary.smith@company.com", "user")
        print("Added regular user: mary_smith")
    except:
        print("User mary_smith already exists")
    
    try:
        database.add_user("bob_wilson", "supply789", "bob.wilson@company.com", "supervisor")
        print("Added supervisor user: bob_wilson")
    except:
        print("Supervisor user bob_wilson already exists")
    
    # Add sample suppliers
    try:
        supplier1_id = database.add_supplier(
            "TechCorp Industries", 
            "Alice Johnson", 
            "alice@techcorp.com", 
            "555-0123", 
            "123 Tech Street, Silicon Valley, CA",
            "tc_api_key_789"
        )
        print(f"Added supplier: TechCorp Industries (ID: {supplier1_id})")
    except:
        print("Supplier TechCorp Industries already exists")
        supplier1_id = 1  # Assume first supplier has ID 1
    
    try:
        supplier2_id = database.add_supplier(
            "Global Supply Co",
            "Mike Chen",
            "mike@globalsupply.com",
            "555-0456",
            "456 Supply Ave, Industrial Park, NY",
            "gsc_api_key_456"
        )
        print(f"Added supplier: Global Supply Co (ID: {supplier2_id})")
    except:
        print("Supplier Global Supply Co already exists")
        supplier2_id = 2  # Assume second supplier has ID 2
    
    # Add sample products
    try:
        product1_id = database.add_product(
            "Laptop Computer", 
            "LAPTOP-001", 
            "High-performance business laptop", 
            "Electronics", 
            25, 5, 100, 899.99, supplier1_id
        )
        print(f"Added product: Laptop Computer (ID: {product1_id})")
    except:
        print("Product Laptop Computer already exists")
    
    try:
        product2_id = database.add_product(
            "Office Chair", 
            "CHAIR-002", 
            "Ergonomic office chair with lumbar support", 
            "Furniture", 
            50, 10, 200, 249.99, supplier2_id
        )
        print(f"Added product: Office Chair (ID: {product2_id})")
    except:
        print("Product Office Chair already exists")
    
    try:
        product3_id = database.add_product(
            "Wireless Mouse", 
            "MOUSE-003", 
            "Bluetooth wireless mouse", 
            "Electronics", 
            100, 25, 500, 29.99, supplier1_id
        )
        print(f"Added product: Wireless Mouse (ID: {product3_id})")
    except:
        print("Product Wireless Mouse already exists")
    
    try:
        product4_id = database.add_product(
            "USB Cable", 
            "CABLE-004", 
            "USB-C to USB-A cable 6ft", 
            "Electronics", 
            8, 20, 1000, 12.99, supplier1_id
        )
        print(f"Added product: USB Cable (ID: {product4_id})")
    except:
        print("Product USB Cable already exists")
    
    print("Database seeding completed successfully!")
    print("\nSample login credentials:")
    print("Admin: admin / admin123")
    print("Manager: john_doe / warehouse2023") 
    print("User: mary_smith / inventory456")
    print("Supervisor: bob_wilson / supply789")

if __name__ == "__main__":
    main()