<?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('task_updates', function (Blueprint $table) {
            $table->id();

            $table->foreignId('task_id')
                ->constrained('tasks')
                ->cascadeOnDelete();

            $table->foreignId('team_member_id')
                ->constrained('team_members')
                ->cascadeOnDelete();

            $table->text('message')->nullable();
            $table->unsignedTinyInteger('progress_percent')->default(0); 
            $table->enum('status', ['working', 'blocked', 'done'])->default('working');

            $table->timestamps();

            $table->index(['task_id', 'created_at']);
        });
    }

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