<?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_incoming_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('fixed_asset_incoming_id')
                  ->constrained('fixed_asset_incoming')->onDelete('cascade');
            $table->foreignId('fixed_asset_id')->nullable()
                  ->constrained('fixed_assets')->onDelete('set null');

            // Asset details
            $table->string('asset_name');
            $table->foreignId('category_id')
                  ->constrained('fixed_asset_categories')->onDelete('restrict');
            $table->string('serial_number', 100)->nullable();
            $table->string('model_number', 100)->nullable();
            $table->string('manufacturer', 100)->nullable();

            // Financial
            $table->decimal('unit_price', 15, 2)->default(0);
            $table->integer('quantity')->default(1);
            $table->decimal('total_price', 15, 2)->default(0);

            // Condition on receipt
            $table->enum('condition_on_receipt', ['new', 'good', 'fair', 'poor', 'damaged'])->default('new');

            // Warranty
            $table->date('warranty_start_date')->nullable();
            $table->date('warranty_end_date')->nullable();

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

            $table->index('fixed_asset_incoming_id');
            $table->index('category_id');
        });
    }

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