<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('service_requests', function (Blueprint $table) {
            $table->id();
            $table->foreignId('partner_id')->constrained('partners')->cascadeOnDelete();
            $table->enum('type', ['prelevement', 'consommable', 'reclamation', 'resultat']);
            $table->enum('status', [
                'en_attente', 'assigne', 'collecte', 'non_disponible', 'livre', 'traite', 'ecart',
            ])->default('en_attente');
            $table->json('details')->nullable();
            $table->unsignedInteger('requested_quantity')->nullable();
            $table->unsignedInteger('collected_quantity')->nullable();
            $table->foreignId('assigned_courier_id')->nullable()->constrained('users')->nullOnDelete();
            $table->enum('urgency', ['normal', 'urgent'])->default('normal');
            $table->string('requested_slot')->nullable();
            $table->string('unavailable_reason')->nullable();
            $table->string('photo_path')->nullable();
            $table->timestamp('collected_at')->nullable();
            $table->timestamp('delivered_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('service_requests');
    }
};
