<?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('fixed_asset_return_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('fixed_asset_return_id')
                  ->constrained('fixed_asset_returns')->onDelete('cascade');
            $table->foreignId('fixed_asset_id')
                  ->constrained('fixed_assets')->onDelete('cascade');

            // Condition assessment
            $table->enum('condition_before', ['new', 'good', 'fair', 'poor', 'damaged', 'written_off'])->nullable();
            $table->enum('condition_after', ['new', 'good', 'fair', 'poor', 'damaged', 'written_off'])->nullable();
            $table->text('condition_notes')->nullable();
            $table->boolean('needs_maintenance')->default(false);
            $table->string('return_location', 255)->nullable();

            $table->text('notes')->nullable();
            $table->timestamps();

            $table->index('fixed_asset_return_id');
            $table->index('fixed_asset_id');
        });
    }

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