<?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_variations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('project_id')->constrained()->onDelete('cascade');
            $table->string('name');
            $table->text('description');
            $table->decimal('cost_impact', 12, 2);
            $table->text('reason')->nullable();
            $table->string('status')->default('pending'); // pending, approved, rejected, implemented
            $table->foreignId('raised_by')->constrained('users');
            $table->dateTime('raised_at');
            $table->json('approvals')->nullable(); // Track approvals from different roles
            $table->dateTime('approved_at')->nullable();
            $table->text('rejection_reason')->nullable();
            $table->dateTime('rejected_at')->nullable();
            $table->dateTime('implemented_at')->nullable();
            $table->timestamps();
        });
    }

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