<?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_approvals', function (Blueprint $table) {
            $table->id();
            $table->foreignId('project_id')->constrained()->onDelete('cascade');
            $table->string('approval_type'); // e.g., 'phase_completion', 'document', 'milestone', 'variation', 'design'
            $table->integer('approval_number')->nullable(); // References the item being approved
            $table->string('required_role'); // Role required to approve
            $table->string('status')->default('pending'); // pending, approved, rejected
            $table->foreignId('requested_by')->constrained('users');
            $table->dateTime('requested_at');
            $table->foreignId('approved_by')->nullable()->constrained('users');
            $table->dateTime('approved_at')->nullable();
            $table->text('approval_notes')->nullable();
            $table->text('rejection_reason')->nullable();
            $table->dateTime('rejected_at')->nullable();
            $table->integer('priority')->default(0); // 0 = normal, 1 = urgent
            $table->timestamps();
        });
    }

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