<?php

try {
    $pdo = new PDO('mysql:host=127.0.0.1;dbname=kenyan_pos', 'root', '');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Database connection successful\n";
    
    // Insert restaurant
    $pdo->exec("INSERT INTO restaurants (name, slug, address, phone, email, vat_rate, currency, settings, created_at, updated_at) 
                VALUES ('Test Restaurant', 'test-restaurant', 'Test Address', '+254700000000', 'test@test.com', 16.00, 'KES', '{}', NOW(), NOW())");
    echo "Restaurant created\n";
    
    // Insert branch
    $pdo->exec("INSERT INTO branches (restaurant_id, name, slug, code, address, phone, created_at, updated_at) 
                VALUES (1, 'Main Branch', 'main-branch', 'MAIN001', 'Test Address', '+254700000000', NOW(), NOW())");
    echo "Branch created\n";
    
    // Insert admin user
    $hashedPassword = password_hash('password', PASSWORD_DEFAULT);
    $pdo->exec("INSERT INTO users (restaurant_id, branch_id, name, email, password, phone, role, created_at, updated_at) 
                VALUES (1, 1, 'Admin User', 'admin@test.com', '$hashedPassword', '+254700000000', 'admin', NOW(), NOW())");
    echo "Admin user created\n";
    
    // Insert category
    $pdo->exec("INSERT INTO categories (restaurant_id, name, slug, description, color, sort_order, created_at, updated_at) 
                VALUES (1, 'Main Dishes', 'main-dishes', 'Main course items', '#EF4444', 0, NOW(), NOW())");
    echo "Category created\n";
    
    echo "Test data inserted successfully!\n";
    
} catch(Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}