<?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('serial_repair_history', function (Blueprint $table) {
            $table->id();
            $table->foreignId('product_serial_id')->constrained('product_serials')->cascadeOnDelete();
            $table->unsignedBigInteger('branch_id')->nullable();
            $table->text('description');
            $table->decimal('repair_cost', 12, 2)->nullable();
            $table->string('repaired_by', 100)->nullable();
            $table->date('started_at');
            $table->date('completed_at')->nullable();
            // repaired, unrepairable, returned_to_customer
            $table->string('outcome', 50)->nullable();
            $table->text('notes')->nullable();
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();

            $table->index('product_serial_id');
        });
    }

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