<?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
    {
        // Tasks table (individual cards)
        Schema::create('operations_tasks', function (Blueprint $table) {
            $table->id();
            $table->foreignId('order_item_id')->constrained('operations_order_items')->onDelete('cascade');
            $table->string('title'); // e.g., "Reels #1"
            $table->string('status')->default('pending'); // pending, working, done
            $table->integer('order_column')->default(0); // For sorting within a column
            $table->timestamps();
        });

        // Comments table
        Schema::create('operations_task_comments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('task_id')->constrained('operations_tasks')->onDelete('cascade');
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade'); // Assuming user is logged in
            $table->text('comment');
            $table->timestamps();
        });

        // Activity Logs table
        Schema::create('operations_task_activities', function (Blueprint $table) {
            $table->id();
            $table->foreignId('task_id')->constrained('operations_tasks')->onDelete('cascade');
            $table->foreignId('user_id')->nullable()->constrained('users')->onDelete('set null');
            $table->string('activity_type'); // e.g., 'status_change', 'comment_added'
            $table->text('description'); // e.g., "Moved from Pending to Working"
            $table->timestamps();
        });
    }

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