<?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('project_phases', function (Blueprint $table) {
            $table->id();
            $table->foreignId('project_id')->constrained()->onDelete('cascade');
            $table->string('name'); // e.g., "Project Creation", "Design Phase", etc.
            $table->integer('phase_number'); // 1-12
            $table->string('status')->default('pending'); // pending, in_progress, completed, on_hold
            $table->text('description')->nullable();
            $table->dateTime('planned_start_date')->nullable();
            $table->dateTime('planned_end_date')->nullable();
            $table->dateTime('actual_start_date')->nullable();
            $table->dateTime('actual_end_date')->nullable();
            $table->string('responsible_role')->nullable(); // e.g., 'Admin', 'Moderator', 'On-Site'
            $table->json('required_approvals')->nullable(); // Array of roles that need to approve
            $table->json('completed_approvals')->nullable(); // Track who approved
            $table->text('completion_notes')->nullable();
            $table->integer('progress_percentage')->default(0);
            $table->timestamps();
        });
    }

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