<?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_milestones', function (Blueprint $table) {
            $table->id();
            $table->foreignId('project_id')->constrained()->onDelete('cascade');
            $table->string('name'); // e.g., "Foundation Complete", "Roofing Complete"
            $table->text('description')->nullable();
            $table->dateTime('planned_date')->nullable();
            $table->dateTime('actual_date')->nullable();
            $table->decimal('planned_budget', 12, 2)->nullable();
            $table->decimal('actual_cost', 12, 2)->default(0);
            $table->string('status')->default('pending'); // pending, in_progress, completed, delayed
            $table->boolean('certified')->default(false); // Project Consultant certification
            $table->text('certification_notes')->nullable();
            $table->foreignId('certified_by')->nullable()->constrained('users');
            $table->dateTime('certified_at')->nullable();
            $table->integer('sequence_order')->nullable();
            $table->timestamps();
        });
    }

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