<?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_documents', function (Blueprint $table) {
            $table->id();
            $table->foreignId('project_id')->constrained()->onDelete('cascade');
            $table->string('name');
            $table->string('document_type'); // e.g., 'contract', 'drawing', 'report', 'specification', 'other'
            $table->string('category'); // e.g., 'architectural', 'structural', 'technical', 'compliance'
            $table->text('description')->nullable();
            $table->string('file_path');
            $table->string('file_name');
            $table->integer('file_size')->nullable();
            $table->string('mime_type')->nullable();
            $table->integer('phase_number')->nullable(); // Which phase this doc relates to
            $table->foreignId('uploaded_by')->constrained('users');
            $table->dateTime('uploaded_at');
            $table->string('version')->default('1.0');
            $table->text('upload_notes')->nullable();
            $table->boolean('is_approved')->default(false);
            $table->foreignId('approved_by')->nullable()->constrained('users');
            $table->dateTime('approved_at')->nullable();
            $table->timestamps();
        });
    }

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