<?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";
    
    // Create menu_items table
    $sql = "CREATE TABLE menu_items (
        id bigint unsigned NOT NULL AUTO_INCREMENT,
        restaurant_id bigint unsigned NOT NULL,
        category_id bigint unsigned NOT NULL,
        name varchar(255) NOT NULL,
        slug varchar(255) NOT NULL,
        description text,
        price decimal(10,2) NOT NULL,
        cost_price decimal(10,2) DEFAULT NULL,
        prep_time int DEFAULT 0,
        kitchen_stations json,
        allergens json,
        nutritional_info json,
        image_url varchar(500),
        is_active tinyint(1) DEFAULT 1,
        is_available tinyint(1) DEFAULT 1,
        track_inventory tinyint(1) DEFAULT 0,
        sort_order int DEFAULT 0,
        created_at timestamp NULL DEFAULT NULL,
        updated_at timestamp NULL DEFAULT NULL,
        PRIMARY KEY (id),
        KEY menu_items_restaurant_id_foreign (restaurant_id),
        KEY menu_items_category_id_foreign (category_id)
    )";
    
    $pdo->exec($sql);
    echo "Menu items table created successfully\n";
    
    // Insert a sample menu item
    $pdo->exec("INSERT INTO menu_items (restaurant_id, category_id, name, slug, description, price, prep_time, kitchen_stations, is_active, is_available, created_at, updated_at) 
                VALUES (1, 1, 'Ugali', 'ugali', 'Traditional Kenyan staple food', 100.00, 10, '[\"main\"]', 1, 1, NOW(), NOW())");
    echo "Sample menu item created\n";
    
} catch(Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}