<?php

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

return new class extends Migration
{
    /**
     * Run the database seeds.
     */
    public function up(): void
    {
        Schema::create('driver_work_areas', function (Blueprint $table) {
            $table->id();
            $table->foreignId('driver_id')->constrained('users')->onDelete('cascade');
            $table->foreignId('working_area_id')->constrained('working_areas')->onDelete('cascade');
            $table->boolean('is_active')->default(true);
            $table->integer('priority')->default(1); // أولوية المنطقة (1 = الأهم)
            $table->timestamps();
            
            // منع تكرار نفس المنطقة لنفس السائق
            $table->unique(['driver_id', 'working_area_id']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('driver_work_areas');
    }
};
