<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('products', function (Blueprint $table) {
            $table->foreignId('unit_id')->nullable()->after('supplier_id')->constrained('units')->cascadeOnDelete('set null');
            $table->decimal('unit_price', 10, 2)->nullable()->after('unit_id'); // Prix unitaire
            $table->string('barcode')->nullable()->unique()->after('unit_price'); // Code-barres/EAN
            $table->enum('status', ['actif', 'archivé'])->default('actif')->after('barcode');
            $table->boolean('is_equipment')->default(false)->after('status'); // Indique si c'est un équipement
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('products', function (Blueprint $table) {
            $table->dropForeign(['unit_id']);
            $table->dropColumn(['unit_id', 'unit_price', 'barcode', 'status', 'is_equipment']);
        });
    }
};