<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // First, update the enum to include new roles
        DB::statement("ALTER TABLE users MODIFY COLUMN role ENUM('admin', 'manager', 'cashier', 'waiter', 'kitchen', 'inventory_manager', 'accountant') DEFAULT 'cashier'");
        
        // Add any additional columns if needed
        Schema::table('users', function (Blueprint $table) {
            // Add employee_id for better user identification
            $table->string('employee_id')->nullable()->unique()->after('id');
            
            // Add department field
            $table->string('department')->nullable()->after('role');
            
            // Add shift information
            $table->json('shift_schedule')->nullable()->after('permissions');
            
            // Add emergency contact
            $table->string('emergency_contact')->nullable()->after('phone');
            
            // Add hire date
            $table->date('hire_date')->nullable()->after('emergency_contact');
            
            // Add salary/wage information (optional)
            $table->decimal('hourly_rate', 8, 2)->nullable()->after('hire_date');
            
            // Add notes field for managers
            $table->text('notes')->nullable()->after('hourly_rate');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn([
                'employee_id',
                'department',
                'shift_schedule',
                'emergency_contact',
                'hire_date',
                'hourly_rate',
                'notes'
            ]);
        });
        
        // Revert enum to original values
        DB::statement("ALTER TABLE users MODIFY COLUMN role ENUM('admin', 'manager', 'cashier', 'waiter', 'kitchen') DEFAULT 'cashier'");
    }
};