<?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::create('field_changes', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('related_id');
            $table->enum('related_type', ['task', 'project'])->default('task');
            $table->string('field_name');
            $table->text('old_value')->nullable();
            $table->text('new_value')->nullable();
            $table->unsignedInteger('changed_by');
            $table->timestamps();

            $table->index(['related_id', 'related_type']);
            $table->index('changed_by');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('field_changes');
    }
};
